• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown

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,


I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic