Apply hibernate annotation on Product and Category design in Many to Many association

Posted on 2009-02-18
Last Modified: 2012-06-21
I am new and studying Hibernate Annotation but unfortunately I have no idea how to startup to design the Product & Category in Java. Hopefully someone can provide guidelines in order for me to proceed.

1) Design Product and Category classes with hibernate annotation so that I can easily add product, add category, and assign product to category on the user interface section.

2) A category has a many to many relationship with a product.

Table schema:
product_id (PK,autonumber)

cat_id (PK, autonumber)

cat_id (PK, FK references Category)
product_id (PK, FK references Product)
display_sequence (int)

So how do I map these associations in JAVA ? Also what are the best syntax to create the composite primary key on the Category_Product table ?

I  know there are few syntaxes in the following, but unsure which are the best to apply for what kind of scenario.
- annotate the component property as @Id and make the component class @Embeddable
- annotate the component property as @EmbeddedId
- annotate the class as @IdClass and annotate each property of the entity involved in the primary key with @Id

Can anyone help me with this. Will really appreciate it.
Thanks a lot in advance.

Question by:wintersun
    1 Comment
    LVL 92

    Accepted Solution

    Well start by creating Product and Category bean classes
    I'd suggest not using a composite key for Category_Product, and instead add a generated id to use as the pk

    let me know when you have that and we'll go to the next step


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now