This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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 ...
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Regarding Hibernate Relationship Mappings - Srinivas

Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr. Srinivas,

Hope that all is well.

I have an issue with Hibernate Mappings. They seem to work well when mapping two related objects that have
composite id's, as long as the mapping does not involve id's in the two objects.

I can map an order to many requests by having the request as an attribute List in the order class. Then in the
getter for the List of requests I can have the following annotation:

In the request class I can have an attribute of the order class as:

and in the setter for that attribute the annotation @ManyToOne with the appropriate column mappings. This successfully
completes the mapping between the two classes.

However, if the two model classes have each a composite primary key, and the column in common between these
two classes is part of each class primary key, then I get an error trying to establish a relationship as described above.

The error that I get is: "No column specified in relationship", even though the column was specified.

The way I tried to establish the relationship was:

- In the invoice class I have a List of type details as: List<Details> details;

- Just above the getter for the above list, I have the annotation: @OneToMany (mappedBy = "invoice")

- In the details class I have an attribute of type invoice as: Invoice invoice;

- Just above the getter for the above invoice attribute I have an @ManyToOne annotation, then I have
an @MapsId("invoiceId") in the next line, and then an @JoinColumns with the name="invoiceCode"

Everything seems to follow the first example blueprint, the only difference is that the column is in both
models composite primary keys in the second one.

Any thoughts, suggestions, or answers are greatly appreciated.

Have a great day.

Kind regards,


Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
the value of filler advertising in 2021
    Bookmark Topic Watch Topic
  • New Topic