I think you need to use an intermediate entity class (e.g., a class GroupProduct) and map one-to-many associations between it and the Group and Product classes. Alternatively, map the join table to a collection of components.
In your case, since it appears there's no ID column for the GROUP_PRODUCT table, you'd probably want to use the component collection method. Create your GroupProduct class, which will be very simple. Then map the Group and Product to use it. Example below for Product (may have typos, didn't write out test code)
Now to add to your set (assuming the correct constructor):
These are the two approaches outlined by Bauer and King in Java Persistence for Hibernate. I'm not sure there's a way you can add the extra column otherwise. If anybody else on the Ranch knows, I'd love to see the answer, but I've always used the intermediate entity class myself.
There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Joined: Jul 10, 2005
Thankyou for your detailed response. I did try the way you suggested. Although I dont see any error - but nothing is being inserted into GroupProduct table. I added what you provided in Product.hbm.xml
Without seeing your full mapping files, etc., it's hard to isolate the cause of the problem.
I'd recommend as a next step downloading the Caveat Emptor example project on Hibernate.org. The native project is the one you'll want. Look at the mappings and the comments in the auction.model package, specifically Category.hbm.xml - there some good comments about the various approaches you can take.
I am facing problem in composite-element mapping of hibernate. My expected relation is many to many in document and task. That is a task may have multiple documents and a document may have assigned to multiple task. Relational table will contain both foregin key with additional column. In attachment i have given the tables structures.
My Task hbm file:
My document hbm file:
I have created all mapping files as you said. My question what will be the java code for inserting in TM_TASK table as well as for TM_TASKDOCS table. And what will be the TaskDocsInfo class exactly. where I have to create the composite class instance and have to assing this instance? I have tried with the following code but fails