[jboss-user] [EJB3] - OneToMany bidirectional with composite PKs
Pasquale Imbemba
do-not-reply at jboss.com
Thu Oct 13 09:13:37 EDT 2011
Pasquale Imbemba [http://community.jboss.org/people/pi4630] created the discussion
"OneToMany bidirectional with composite PKs"
To view the discussion, visit: http://community.jboss.org/message/631562#631562
--------------------------------------------------------------
Hi,
I kindly ask for help for mapping OneToMany bidirectional with ManyToOne. Consider the following (for the sake of semplicity):
I have two tables, FOO and BAR. Foo has a PK which is named "ID". BAR has a composite PK, which is made of ID_FOO (i.e. it's the FK to FOO) and ID.
For both tables, there're the realitve entites, namely Foo and Bar.
Foo has the field id annotated with @Id and contains a field of type Bar (say 'bar') which has the @OneToMany mapped by "foo" - which is the field of the Bar class. On this field (foo) of the Bar class, I have @ManyToOne and @JoinColumn(name="ID_FOO") annotated. Foo also has the composite primary key field fooPk of type FooPK, with @EmbeddedId annotated. The FooPK refers to the two fields, i.e. the ones mapping ID and ID_FOO.
With this config, I get the error "org.hibernate.MappingException: Repeated column in mapping for entity:" Foo. when deploying.
If I change the configuration, and use only OneToMany JoinColumn on ID_FOO on the Foo entity bean and delete the reference back on the Bar entity, it works - but of course, I can't navigate from Bar to Foo...
So, how do I config the OneToMany bidirectionally, when the "weak" table/class has a composite primary key?
Thanks,
~pasquale
--------------------------------------------------------------
Reply to this message by going to Community
[http://community.jboss.org/message/631562#631562]
Start a new discussion in EJB3 at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20111013/acc8e0d9/attachment.html
More information about the jboss-user
mailing list