openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dick <michael.d.d...@gmail.com>
Subject Re: Merge of an already managed instance before query execution
Date Wed, 28 Jan 2009 16:34:06 GMT
Hi,

Are you executing the queries using the same EntityManager, or are there
different EM instances? Also are you using a DataCache? I believe there have
been similar issues reported with caching enabled.

If you're using the same em then you shouldn't need to flush or call merge.
The state of the managed entities will be stored in the PersistenceContext
and your changes will be visible.

If you're using a separate EM instance for the second round of queries then
you'll have to flush your changes. You still shouldn't require a merge
though, unless I'm forgetting something obvious.

regards,
-mike


On Tue, Jan 27, 2009 at 3:26 AM, jinfeng <jonas.g.pettersson@gmail.com>wrote:

>
> 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
> instances)
> 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."
>
> http://openjpa.apache.org/builds/1.2.0/apache-openjpa-1.2.0/docs/manual/jpa_overview_em_lifecycle.html
> 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!
>
> /JP
>
>
>
>
>
>
>
> --
> View this message in context:
> http://n2.nabble.com/Merge-of-an-already-managed-instance-before-query-execution-tp2223223p2223223.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

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