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.
cat_id (PK, autonumber)
cat_id (PK, FK references Category)
product_id (PK, FK references Product)
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.