openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinfeng <>
Subject Merge of an already managed instance before query execution
Date Tue, 27 Jan 2009 09:26:39 GMT

Dear OpenJPA users,

I have a question regarding the merge() operation, and its behaviour. 

Basically, my implementation executes like this:

1) client starts TX (outside my application)
2) my code executes a number of queries (i.e. reads managed entity
3) my code updates the state of these entities (i.e. writes already managed
entity instances)
4) my code merges the modified entities (which have NOT become detached)
5) my code executes a number of queries on the merged entites
6) client commits TX (outside my application)

In order for the queries in step 5 to see the updates made in step 3, an
explicit call to flush() seems to be required. It does not matter if the
FlushType is set to AUTO. However, if I invoke clear() prior to the merge()
in step 4, the behaviour is different and my updates are automatically
flushed before the queries in step 5.

My question is if someone can explain this behaviour. I have noticed the
definition of the merge() operation:

"If A is an existing managed entity, it is ignored. However, the merge
operation still cascades as defined below."
2. Entity Lifecycle Management 

I also tried to experiment with the OpenJPA properties "FlushBeforeQueries"
and "IgnoreChanges" with no luck. 

I would like to rather not have to call flush(), but instead leave this to
the JPA implementation when it is required. Maybe I am thinking wrong here?
Any ideas would be very appreciated! 

Thanks for your attention!


View this message in context:
Sent from the OpenJPA Users mailing list archive at

View raw message