• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding Hibernate Relationship Mappings - Srinivas

 
R Diaz
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • 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"
specified.

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,

Rudi


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic