openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Struberg (Commented) (JIRA)" <>
Subject [jira] [Commented] (OPENJPA-2107) ManagedCache conflict due adding an entity 2 times in the same query.
Date Thu, 12 Jan 2012 13:05:39 GMT


Mark Struberg commented on OPENJPA-2107:

I now locally reproduced this with a simple Entity. The problematic pattern is to create an
entity instance, em.persist it and do a query containing this new entity in the _same_ transaction!
The effect only appears if other entities exists which would be returned by the query.


Semester sem = new Semester();

Query q = em.createQuery("select s from Semester as s where s.season=:season", Semester.class);
q.setParameter("season", SemesterDTO.Season.S);
List<Semester> semesters = q.getResultList();
Assert.assertTrue(semesters.size() > 1); <-- this line crashes!

I'm currently using the following properties in our persistence.xml

            <property name="openjpa.DynamicEnhancementAgent" value="false"/>

            <!-- disable prepared statement caching -->
            <property name="openjpa.jdbc.QuerySQLCache" value="false"/>

            <property name="openjpa.DataCache" value="false"/>

            <property name="openjpa.Log" value="log4j"/>
            <property name="openjpa.PostLoadOnMerge" value="true" />
            <property name="openjpa.DetachState" value="loaded(DetachedStateField=true)"/>
            <property name="openjpa.Compatibility" value="IgnoreDetachedStateFieldForProxySerialization=true"/>

            <property name="openjpa.jdbc.MappingDefaults"
                      value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/>

            <!-- use class per table strategy -->
            <property name="openjpa.Sequence" value="class-table(Table=SEQUENCES, Increment=20,

> ManagedCache conflict due adding an entity 2 times in the same query.
> ---------------------------------------------------------------------
>                 Key: OPENJPA-2107
>                 URL:
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: kernel
>    Affects Versions: 2.2.0
>            Reporter: Mark Struberg
>            Assignee: Mark Struberg
>             Fix For: 2.2.0
> I have a complex query which creates the following error:
> <openjpa-2.2.0-tiss-2-rexported nonfatal user error> org.apache.openjpa.persistence.ArgumentException:
Cannot load object with id "26301".  Instance ""
with the same id already exists in the L1 cache.  This can occur when you assign an existing
id to a new instance, and before flushing attempt to load the existing instance for that id.
> FailedObject:
> 	at org.apache.openjpa.kernel.ManagedCache.add(
> 	at org.apache.openjpa.kernel.BrokerImpl.setStateManager(
> 	at org.apache.openjpa.kernel.StateManagerImpl.initialize(
> 	at org.apache.openjpa.kernel.StateManagerImpl.initialize(
> 	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(
> It seems that this entity gets loaded from the db twice in the same query.
> While hitting the problem, the StateManagers have the following _flags:
> orig _flags= 602 = 0010 0101 1010 SAVE LOADED READ_LOCKED OID_ASSIGNED FLUSHED  
> sm   _flags= 16  = 0000 0001 0000 READ_LOCKED
> And it is really only 1 instance which makes this problem. If I set the 'orig' variable
to null in the debugger, the test runs fine.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message