The moose likes Object Relational Mapping and the fly likes two parents, one child, ora-02291 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "two parents, one child, ora-02291" Watch "two parents, one child, ora-02291" New topic

two parents, one child, ora-02291

Pablo Marmol

Joined: Aug 23, 2010
Posts: 13

I have a simple issue about parent/child relations. Something is wrong when i persist three instances at same transaction, that is, one child and two parents. The child have ManyToOne relations to the parent1 and the parent2, and the two parents have one OneToMany relation (each one) to the child. The child table have two foreign keys to its parents. This is the code:




And this is the code that use the entities:

In my investigation about this i find that this works when the child have only one parent.

I try another way: I drop de FK constraints in the database, then i execute the code, and then i recreated the FK constraints... and voila!!! no errors creating the FK constraints ?¿?¿?¿?¿? That signals that the data is right, but anything is wrong and i dont understand... Could you help me please?

I use java 6, weblogic 10.3.4 (jpa 1 i think), oracle 11.

Thank you very very much... i'm obfuscated.
Pablo Marmol

Joined: Aug 23, 2010
Posts: 13
More info:

The code is executed within an EJB, using EntityManager and container-managed transactions.
Using Postgresql is the same.
The code works on glassfish3 adding "allocationSize = 1" to the "@SequenceGenerator" annotations. But in WLS 10.3.4 don't works. Glassfish3 comes with JPA2, and WLS 10.3.4 only JPA1, but i'm not using anything of v2.

searching... (thanks in advance)
Pablo Marmol

Joined: Aug 23, 2010
Posts: 13

Add this to persistence.xml:
<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>

I agree. Here's the link:
subject: two parents, one child, ora-02291
jQuery in Action, 3rd edition