openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adme Admirolas <admiro...@gmail.com>
Subject Entities insertion order
Date Mon, 26 Mar 2012 14:05:09 GMT
Hello,

I'm facing problems, when I persist JPA entities. Here is scenario:

My app is runing under WebSphere Comunity Edition (Apache Geronimo). I'm
using CDI, and inject EntityManager and UserTransaction into named bean. I
have entity, that we can call MainEntity. It has 2 "@ManyToOne(optional =
false, fetch = LAZY, cascade = { PERSIST, REFRESH })" relationship to other
entities, lets call them MinorEntity. So, when i commit UserTransaction,
the JPA first of all inserts Main, then MinorEntity, and then try to update
MainEntity table again. The problem is, that i have not null constraint on
database.
I googled a little bit, and found that i should use OpenJPA @ForeignKey
annotation, to force OpenJPA first of all insert MinorEntity. But this
didn't helped to me, the insert order is still incorrect.

The strangest thing, is that i have unit test, that tries to simulate this
situation using Resource Local transaction type. And it does not fails.

What I'm doing wrong?

Here is persistence.xml of container managed persistence context:

 <persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
>     <persistence-unit name="PRNUBEMJPA" transaction-type="JTA">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>         <jta-data-source>jdbc/PRNUBEM</jta-data-source>
>         <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
>         <validation-mode>AUTO</validation-mode>
>         <properties>
>             <property name="openjpa.jdbc.Schema" value="PRNUBEM"/>
>             <property name="openjpa.jdbc.DBDictionary"
> value="org.apache.openjpa.jdbc.sql.DB2Dictionary" />
>             <property name="openjpa.Log" value="DefaultLevel=WARN,
> Runtime=INFO, Tool=INFO, SQL=TRACE"/>
>             <property name="openjpa.ConnectionFactoryProperties"
> value="printParameters=true"/>
>             <property name="openjpa.InverseManager" value="true"/>
>         </properties>
>     </persistence-unit>
> </persistence>
>


And here is persistence.xml of resource local persistence context:

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
> http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
>     <persistence-unit name="PRNUBEMJPA" transaction-type="RESOURCE_LOCAL">
>
>  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>         <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
>         <validation-mode>AUTO</validation-mode>
>         <properties>
>             <property name="openjpa.ConnectionURL"
>                 value="jdbc:db2://localhost:50000/PRNUBEM" />
>             <property name="openjpa.ConnectionDriverName"
>                 value="com.ibm.db2.jcc.DB2Driver" />
>             <property name="openjpa.ConnectionUserName" value="****" />
>             <property name="openjpa.ConnectionPassword" value="***" />
>             <property name="openjpa.jdbc.Schema" value="PRNUBEM"/>
>             <property name="openjpa.jdbc.DBDictionary"
> value="org.apache.openjpa.jdbc.sql.DB2Dictionary" />
>             <property name="openjpa.Log" value="DefaultLevel=WARN,
> Runtime=INFO, Tool=INFO, SQL=TRACE"/>
>             <property name="openjpa.ConnectionFactoryProperties"
> value="printParameters=true"/>
>             <property name="openjpa.InverseManager" value="true"/>
>         </properties>
>
>     </persistence-unit>
> </persistence>
>


Admirolas

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message