|
|
Re: Lazy-loaded basic attribute never refreshed [message #1385352 is a reply to message #1385339] |
Thu, 05 June 2014 19:01 |
Peter Nehrer 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?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05277 seconds