You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by kostellodon <do...@citi.com> on 2012/02/29 18:26:04 UTC
Lifecycle listener invoked on Query
I am using OpenJPA 1.2.3 in WebSphere 7. I have an entity that I have added
an entity listener via annotation. In the entity listener class, I have
defined PostPersist, PostUpdate, and PostRemove methods.
I am using a web service. Within the web service lifecycle, there are two
different methods that deal with my entity object. In one, I am just doing
a fetch by creating a query & invoking query.getSingleResult(). In the
other method, I am updating the object. Both of these methods are causing
the lifecycle PostUpdate method to be invoked. I believe that the second is
correct, but I'm not sure why PostUpdate is being called by the query. My
understanding is that PostLoad only should be invoked.
The following is my stack trace from the invocation by the Query method
(AuditListener.updateCheck is my lifecycle PostUpdate method):
AuditListener.updateCheck(Object) line: 66
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not
available [native method]
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 60
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 37
Method.invoke(Object, Object...) line: 611
BeanLifecycleCallbacks.makeCallback(Object, Object, int) line: 85
LifecycleEventManager.makeCallbacks(Object, Object, ClassMetaData, int,
Collection) line: 340
LifecycleEventManager.fireEvent(Object, Object, ClassMetaData, int) line:
302
BrokerImpl.fireLifecycleEvent(Object, Object, ClassMetaData, int) line: 690
StateManagerImpl.fireLifecycleEvent(int) line: 352
StateManagerImpl.afterFlush(int) line: 1008
BrokerImpl.flush(int) line: 2052
BrokerImpl.flushSafe(int) line: 1927
BrokerImpl.flush() line: 1698
QueryImpl.isInMemory(int) line: 956
QueryImpl.execute(int, Map) line: 838
QueryImpl.execute(Map) line: 779
DelegatingQuery.execute(Map) line: 525
QueryImpl(QueryImpl).execute() line: 254
QueryImpl(QueryImpl).getSingleResult() line: 317
Should this be happening? Is there a way I can prevent it?
Don
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lifecycle-listener-invoked-on-Query-tp7329975p7329975.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Lifecycle listener invoked on Query
Posted by Pinaki Poddar <pp...@apache.org>.
I think the current OpenJPA status is such that if you want dirty objects in
an in-flight transaction be included in the result of a query, OpenJPA will
flush the dirty objects to database and then evaluate the query on database
if openjpa.IgnoreChanges=false.
If openjpa.IgnoreChanges=true, OpenJPA will ignore the dirty in-memory
objects and evaluate the query on the unflushed database.
>From your description it looks like you want openjpa.IgnoreChanges=false.
But that setting will also cause a flush and hence a post update
notification.
I have not taken a look at the current code and simply trying to recollect
from my memory. Others may be able to advise you on other options or
solutions.
Also note that using proprietary OpenJPA API, you can query *only* on the
in-memory objects (may work here as you seem to be looking for a single
object).
-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lifecycle-listener-invoked-on-Query-tp7329975p7330576.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Lifecycle listener invoked on Query
Posted by kostellodon <do...@citi.com>.
I'm not using either a data cache or a query cache. Do you mean
IgnoreChanges? I set a value of IgnoreChanges=true, and that caused the
first call to go away. However, that doesn't work for me, since I can't
always assume my object isn't dirty - methods earlier in my transaction may
have changed it. I want the object that's in the entity manager returned,
and don't need it flushed before the end of the transaction.
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lifecycle-listener-invoked-on-Query-tp7329975p7330503.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: Lifecycle listener invoked on Query
Posted by Pinaki Poddar <pp...@apache.org>.
The likely cause of this observation is:
the query determined that current cache holds dirty objects that can affect
the result of the query. Hence it flushed them and a post update was
notified.
Try specifying openjpa.IgnoreCache=true
-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Lifecycle-listener-invoked-on-Query-tp7329975p7330296.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.