Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Lazy-loaded basic attribute never refreshed
Lazy-loaded basic attribute never refreshed [message #1385159] Wed, 04 June 2014 16:43 Go to next message
Peter Nehrer is currently offline Peter NehrerFriend
Messages: 241
Registered: July 2009
Senior Member
Hi,

I have an entity with a lazy-loaded String attribute. The entity is
configured with a limited cache expiry and supports shared cache.

When loading the objects thru a read-only query with shared cache
enabled, I never see the lazy-loaded attribute refreshed. When the
object itself expires, I see a refresh query with the default (eager)
fetch group but the lazy attribute is never included?

Is that the expected behavior? Is anyone else seeing this?

Thanks!

--Peter
Re: Lazy-loaded basic attribute never refreshed [message #1385339 is a reply to message #1385159] Thu, 05 June 2014 17:38 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
The refresh query for the entity with the default fetch group should reset the fetch group - the next access of something that wasn't included will force them to be refreshed from the database. Are you seeing the lazy loaded string getting refreshed if you access it after the object was refreshed?
Re: Lazy-loaded basic attribute never refreshed [message #1385352 is a reply to message #1385339] Thu, 05 June 2014 19:01 Go to previous messageGo to next message
Peter Nehrer is currently offline Peter NehrerFriend
Messages: 241
Registered: July 2009
Senior Member
No, I'm not seeing that and can reproduce this problem easily -- after
the object expires and a refresh query is executed when the object is
built, the lazy field isn't updated. When I step through the getter for
that field I find that there is no fetch group on the object
(org.eclipse.persistence.queries.FetchGroupTracker._persistence_getFetchGroup()
returns null) and the generated
org.eclipse.persistence.queries.FetchGroupTracker._persistence_isAttributeFetched(String)
returns null in that case no matter what.

The only way to refresh that field is to do an explicit refresh or query
that includes that attribute in the fetch group.

I tried to hack around it by returning false in that situation:

In MyEntity.java:
public boolean _persistence_isAttributeFetched(String attributeName) {
FetchGroupTracker tracker = (FetchGroupTracker) this;
if ("lazyField".equals(attributeName)) {
if (tracker._persistence_getFetchGroup() == null)
return false;
}

FetchGroup fetchGroup = tracker._persistence_getFetchGroup();
if (fetchGroup == null)
return true;

return fetchGroup.containsAttributeInternal(attributeName);
}


But then there are further problems as there's no active session on that
object either (even though we're in the middle of an active
EntityManager and the object is still managed, returned from a read-only
query):

Caused by: java.lang.NullPointerException
at
org.eclipse.persistence.internal.jpa.EntityManagerImpl.processUnfetchedAttribute(EntityManagerImpl.java:2831)
at com.example.model.MyEntity._persistence_checkFetched(MyEntity.java)
at com.example.model.MyEntity._persistence_get_lazyField(MyEntity.java)
at com.example.model.MyEntity.getLazyField(MyEntity.java:161)
....

It sounds like a bug unless there's something wrong with what I'm doing,
but I can't find anything. This happens with multiple classes in
multiple usage scenarios (all readonly, lazy-loaded, cached/expired
objects).

The only work-around that I know of (other than explicit refresh, which
I can't do on read-only objects) is to avoid @Basic(fetch = FetchType.LAZY).

On 6/5/14, 1:38 PM, Chris Delahunt wrote:
> The refresh query for the entity with the default fetch group should
> reset the fetch group - the next access of something that wasn't
> included will force them to be refreshed from the database. Are you
> seeing the lazy loaded string getting refreshed if you access it after
> the object was refreshed?
Re: Lazy-loaded basic attribute never refreshed [message #1385684 is a reply to message #1385352] Tue, 10 June 2014 13:35 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Please file a bug and vote for it.
Re: Lazy-loaded basic attribute never refreshed [message #1385739 is a reply to message #1385684] Tue, 10 June 2014 20:23 Go to previous message
Peter Nehrer is currently offline Peter NehrerFriend
Messages: 241
Registered: July 2009
Senior Member
Created https://bugs.eclipse.org/bugs/show_bug.cgi?id=437085. Thanks.
Previous Topic:MOXy failes to serialize list of objects
Next Topic:UnaryTableSequence per entity vs single table-sequence table
Goto Forum:
  


Current Time: Fri May 10 19:26:15 GMT 2024

Powered by FUDForum. Page generated in 0.03412 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top