Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

Own UpdateManager - but issue with "isPersistent" and "isFlushed" for new JPA entities

$
0
0
Dear Community,

For our project we added an own UpdateManager for OpenJPA. We use the
UpdateManager to do "explicit updates" for our JPA entities.
This means that we use the UpdateManager to filter the set of JPA objects
and to pass forward only those JPA entities that we want be explicitly
insert or update in the database.

The UpdateManager is defined in the persistence.xml and working fine:

<property name="openjpa.jdbc.UpdateManager" value="OurOwnUpdateManager"
/>

However we have an issue with new JPA entities we create within our use
case / transaction.
The issue: The new entities are created at the beginning and known to the
EntityManager when we create them.
They are in the initial newState with isFlush=false and isPersist = false.
So far so good.

However when we run a "flush() operation" - e.g. to update the another
objects. The new objects change the state to isPersist and isFlushed.
However no update is happening on the database.
Even if they are not passed from our UpdateManager to the
BatchingConstraintUpdateManager.update().

At the end when we pass the objects (e.g. in the third flush operation)
the EntityManager thinks that the objects are already existing and does an
update on the tables instead of the an insert.
And so our application fails.

Question:
Is there are chance to prevent OpenJPA to set new created objects to
isPersist and isFlushed?
Is it the expected behavior of OpenJPA (meaning that the EntityManager
might change the state of objects during the flush operations that are not
passed to the BatchingConstraintUpdateManager.udpate... ).
Is there a way to reset the state of the objects to tell OpenJPA in one of
the following flushs to do the insert instead of an update?

Looking forward to any helpful hints, tips and explanations! Thanks in
advance ; )

Cheers
Christoph

Viewing all articles
Browse latest Browse all 5648

Trending Articles