This content has been marked as final. Show 4 replies
I don't know what OpenJPA defaults to but the following works fine in EclipseLink using "database" or "both".
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
Is there a reason you need to use OpenJPA. I ask this because EclipseLink is JPA 2.0 compliant, current and flexible.
Hi Michael, thanks for your reply. I'm implementing using openJpa because I've found the FK value setting in child elements simpler than in eclipselink, as this link says:
I have for example 1 user with 2 email objects associated: when I persist in my MySQL db using eclipselink (following user's guide and other web tutorials) I have 1 user record and 2 email records (in respective tables), but in each email the FK column is null (I'd need to don't call the email.setUser setter method).... I tried it in openJpa setting that options above and it works fine, every email has its FK linking to the right user...
Although it's not the subject of this post I try to ask you: is this possibile even in EclipseLink? Have you any suggestion about setting FK value in db using eclipselink without calling email.setUser setter method?
Thank you very much,
As the link states, bidirectional relationship maintenence is not provided for in Java and was excluded from JPA despite it existing in EJB2.0. EclipseLink supports EJB2.0, and does have this feature available, but I would strongly discourage it - personally I found it difficult to support and maintain references that use it. Generally it is as simple as putting a helper method on one entity that sets the references on both ie User.setEmail() could set the user's email, and if the email is not null, the email's user. This makes it more clear how and why the email's user is or isn't set, especially if the objects are ever reused outside of a persistence context. This is somewhat described in http://en.wikibooks.org/wiki/Java_Persistence/Relationships under common problems
That said, the EclipseLink feature can be turned on using a customizer to call setRelationshipPartnerAttributeName on the mappings for both sides of the relationship.