FetchGroup for relation attributes [message #1346759] |
Sat, 10 May 2014 16:39  |
Eclipse User |
|
|
|
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 #1347524 is a reply to message #1346759] |
Sun, 11 May 2014 00:34  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.08372 seconds