• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to map ManyToOne relationship with Composite key?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't you also have to uncomment out the IdClass annotations, etc. in the parent class?

Mark
 
Ricardo Preston
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I do if I'm using the FormKey class, as well as uncommenting the @EmbeddedId line.
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic