This content has been marked as final.
Show 2 replies
-
1. Re: @ManyToOne mappedBy not allowed?
tsar_bomba Mar 10, 2006 1:26 PM (in response to mazz)I'm very new to EJB3 but have not had a problem doing stuff like this so far, so bear with me.
If you used a mappedBy on your OneToMany to the field in the ManyToOne class...the relationship should be automatic (implied)....otherwise you could use a @JoinColumn annotation to specify the field, if you must.
See here:
http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html#d0e1018 -
2. Re: @ManyToOne mappedBy not allowed?
mazz Mar 10, 2006 9:33 PM (in response to mazz)Thanks for pointing out that URL. I did find the exact answer to my question there:
http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html#entity-mapping-association-collections
Section 2.2.5.3.2.1 answers the question directly:
Since many to one are (almost) always the owner side of a bidirectional relationship in the EJB3 spec, the one to many association is annotated by @OneToMany( mappedBy=... )
...
To map a bidirectional one to many, with the one-to-many side as the owning side, you have to remove the mappedBy element and set the many to one @JoinColumn as insertable and updatable to false. This solution is obviously not optimized from the number of needed statements.