• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Many-To-Many w/ Composite Key

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am hoping someone can guide me through this issue. I have solved this problem earlier using JPA, but I now must use Hibernate only.

This is the annotation I used in JPA.




The goal is a document may belong to many groups. A group may have many documents. How I handled this using JPA was create a Document_Collection table. I have done the same in Hibernate by creating a table called document_collection_groupXref.

I've tried to follow the "Java Persistence with Hibernate" book in creating my solution. Here are the hibernate files


jtdiDocument.hbm.xml




CollectionGroup.hbm.xml





Lastly, DocumentCollectionGroupXref.hbm.xml





I've thoroughly confused myself on how to proceed. In JPA I never had to touch the xref table. All I had to do was add the collection group to the Document class and add the document to the CollectecionGroup Class and JPA would do all the mapping to the cross-reference table.

What the Hibernate book tells me to maintain a Set of DocumentCollectionGroupXref classes in the Document class and in the CollectionGroup Class. However, this approach assumes a Group already exist.

Any counsel would be greatly appreciated.


Russ
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic