File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes How to map ManyToOne relationship with Composite key? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "How to map ManyToOne relationship with Composite key?" Watch "How to map ManyToOne relationship with Composite key?" New topic
Author

How to map ManyToOne relationship with Composite key?

Ricardo Preston
Greenhorn

Joined: Jan 11, 2010
Posts: 7
Hi all. I'm having great difficulty trying to map a ManyToOne relationship between 2 classes, when one class has a composite primary key. I'm running JBoss 5.0 and Seam.

I have a Form class that has many Rules. If at first I ignore the composite key and just use 1 field as the key, all is fine (though of course I get multiple matches instead of one). The code looks something like this:



Now if I uncomment the 2nd @JoinColumn annotation, I get the error:

org.hibernate.AnnotationException: A Foreign key refering xxx.yyy.Form from xxx.yyy.Rule has the wrong number of column. should be 1


If I create a PK class FormKey.java to hold the form name & version, I then don't know how to construct the annotations in Rule, since I'm no longer joining columns directly, but mapping to a class Form.key instead.

Any ideas? Thanks.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16353

Don't you also have to uncomment out the IdClass annotations, etc. in the parent class?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ricardo Preston
Greenhorn

Joined: Jan 11, 2010
Posts: 7
Yes, I do if I'm using the FormKey class, as well as uncommenting the @EmbeddedId line.
 
 
subject: How to map ManyToOne relationship with Composite key?
 
Two Laptop Bag