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

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.

Who is Participating?
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.