Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » FetchGroup for relation attributes
FetchGroup for relation attributes [message #1346759] Sat, 10 May 2014 20:39 Go to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
Hi, All I am using FetchGroup feature in EclipseLink 2.5.1
I am using the Expression Framework and dynamic entities. My code is like this
ReadAllQuery readAllQuery=...

readAllQuery.setCacheUsage(ObjectLevelReadQuery.DoNotCheckCache);
readAllQuery.dontMaintainCache();
FetchGroup fetchGroup=new FetchGroup();
fetchGroup.addAttribute("Name");
fetchGroup.addAttribute("doomroom.name");
readAllQuery.setFetchGroup(fetchGroup);
results=session.executeQuery(readAllQuery);

Here is the sql executed by eclipselink
Quote:

1. [EL Fine]: sql: 2014-05-10 12:15:20.419--ServerSession(14983258)--Connection(2105963)--Thread(Thread[main,5,main])--SELECT ID, NAME, FXVERSION, DOOMROOM_ID FROM MSTUDENT WHERE NOT ((DOOMROOM_ID IS NULL))
2. [EL Fine]: sql: 2014-05-10 12:15:20.437--ServerSession(14983258)--Connection(2105963)--Thread(Thread[main,5,main])--SELECT ID, FXVERSION, NAME FROM MDOOMROOM WHERE (ID = ?)
bind => [504]
3. [EL Fine]: sql: 2014-05-10 12:15:20.451--ServerSession(14983258)--Connection(2105963)--Thread(Thread[main,5,main])--SELECT ID, FXVERSION, NAME FROM MDOOMROOM WHERE (ID = ?)
bind => [502]


Here are something I observed.
1. I do not have sql line 2 and 3 in the log above If I do not use em.getEntityManagerFactory().getCache().evictAll() before query. The line 2 and line 3 are sql to load related entities(doomroom). I thought cache is not checked since I have readAllQuery.setCacheUsage(ObjectLevelReadQuery.DoNotCheckCache); How can I ask this particular query not checking cache.

2. Not matter whether I evict all object from cache or not, the related entities always have all attributes loaded. The sql indicated only id, version and specified property (name) is loaded, but returned object has every properties loaded. Could it possible that the returned object is not the one from database, but the one in cache?


3. Can I use EntityGraph with Expression framework?

Help is really appreciated.

thanks
-jason
Re: FetchGroup for relation attributes [message #1347515 is a reply to message #1346759] Sun, 11 May 2014 04:30 Go to previous messageGo to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I found two ways to make this works
First, if I
readAllQuery.setCascadePolicy(ObjectLevelReadQuery.CascadeAllParts);

The fetch group is applied to related attributes recursively. I found that the cache setting in ReadAllQuery did not apply to related ObjectReadyQuery when it is time to retrieve related entity. Related entities are still read from cache. If cascade is set as above, the cache is ignored.

Another approach: I set all related attributes as join attributes. The fetchGroup is applied recursively as expected.

Can someone give me insight how it behaves like this?

thanks

-jason
Re: FetchGroup for relation attributes [message #1347517 is a reply to message #1346759] Sun, 11 May 2014 04:32 Go to previous messageGo to next message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I found two ways to make this works
First, if I
readAllQuery.setCascadePolicy(ObjectLevelReadQuery.CascadeAllParts);

The fetch group is applied to related attributes recursively. I found that the cache setting in ReadAllQuery did not apply to related ObjectReadyQuery when it is time to retrieve related entity. Related entities are still read from cache. If cascade is set as above, the cache is ignored.

Another approach: I set all related attributes as join attributes. The fetchGroup is applied recursively as expected.

Can someone give me insight how it behaves like this?

thanks

-jason
Re: FetchGroup for relation attributes [message #1347524 is a reply to message #1346759] Sun, 11 May 2014 04:34 Go to previous message
jason zhang is currently offline jason zhangFriend
Messages: 31
Registered: July 2009
Member
I found two ways to make this works
First, if I
readAllQuery.setCascadePolicy(ObjectLevelReadQuery.CascadeAllParts);

The fetch group is applied to related attributes recursively. I found that the cache setting in ReadAllQuery did not apply to related ObjectReadyQuery when it is time to retrieve related entity. Related entities are still read from cache. If cascade is set as above, the cache is ignored.

Another approach: I set all related attributes as join attributes. The fetchGroup is applied recursively as expected.

Can someone give me insight how it behaves like this?

thanks

-jason
Previous Topic:JPQL LEFT JOIN FETCH Results in NPE when DescriptorCustomizer in Place
Next Topic:FetchGroup does not work for Embedded attribute
Goto Forum:
  


Current Time: Thu Jul 30 06:28:32 GMT 2015

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

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