[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] @PostLoad not called on a ReadAllQuery?
|
Instead of,
>> Session session = JpaHelper.getServerSession(emf);
Use,
Session session = ((JpaEntityManager)em.getDelegate()).getActiveSession();
This will be the UnitOfWork in the same persistence context as the
EntityManager.
DeSilentio wrote:
>
> Thanks for the explanation. I think you might be right about the Cache. I
> couldn't really test this before because I was having other difficulties
> on redeployment (per another post). Is there a way to force it to reload
> from outside the cache? I guess you seem to be suggesting that using a
> UnitOfWork will do this, but is it possible to return a ScrollableCursor
> using a UnitOfWork? If so could you provide a simple example of how to do
> so?
>
> Here is my query code (class names obscured):
>
> Session session = JpaHelper.getServerSession(emf);
> ReadAllQuery query = new ReadAllQuery(ClassA.class);
> ExpressionBuilder builder = query.getExpressionBuilder();
>
> // I was using a scrollable cursor but have recently stopped
> // query.useScrollableCursor(pageSize)
>
> query.setSelectionCriteria(expression);
> query.addOrdering(orderingExpression);
>
> result = (Vector) session.executeQuery(query);
> // or
> // cursor = (ScrollableCursor) session.executeQuery(query);
>
>
>
> James Sutherland wrote:
>>
>> In EclipseLink the JPA postLoad event is translated into the native
>> EclipseLink events. Currently it sets the EclipseLink events, postBuild
>> (called when a new object is built from the database), postRefresh
>> (called when an existing object is refreshed from the database),
>> postClone (called whenever EclipseLink clones an object, such as
>> registering an object from the shared cache into the EntityManager
>> persistence context, but also when merging back into the shared cache,
>> and when copying a new object or merged object). So the postLoad on
>> persist/merge is caused by the postClone, which is odd, you may wish to
>> log a bug for this as calling postLoad here does not seem correct.
>>
>> As for why postLoad is not called on your ReadAllQuery, I'm not sure.
>> Can you include the code on how you execute the query. Is the postLoad
>> called when executing JPA queries?
>>
>> My guess is that the object is already in the shared cache, so when you
>> execute the query, you get the existing object from the shared cache, so
>> it is not loaded from the database, so no event. Your query is probably
>> somehow read-only or using the ServerSession, so the object is not
>> cloned. If you used a UnitOfWork, it would be cloned causing the event.
>>
>>
>>
>> DeSilentio wrote:
>>>
>>> Also...
>>>
>>> I am using an non container managed persistent unit although using it
>>> with glassfish.
>>> I believe I am using eclipselink 1.0.2.
>>>
>>> Strangely it looks like the method marked as @PostLoad is being called
>>> when I persist/merge an object of this type.
>>>
>>>
>>> DeSilentio wrote:
>>>>
>>>> Hi,
>>>>
>>>> I'm performing a ReadAllQuery to retrieve a ScrollableCursor. I have a
>>>> method of the class I'm trying to retrieve that is annotated as
>>>> @PostLoad. However, this method does not appear to be called when I use
>>>> the ReadAllQuery. What is the appropriate way to make sure this method
>>>> is called after the query is performed?
>>>>
>>>> Any help appreciated.
>>>>
>>>
>>>
>>
>>
>
>
-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://www.nabble.com/%40PostLoad-not-called-on-a-ReadAllQuery--tp21382406p21438198.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.