Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Related sub entities not loaded - EAGER ignored?
Related sub entities not loaded - EAGER ignored? [message #1004481] Wed, 23 January 2013 10:29 Go to next message
Filipp A. is currently offline Filipp A.
Messages: 49
Registered: February 2010
Member
Hi @All!
i try to get my Object with all related sub entities (NamedQuery loadGroupMembershipWithProfileId), but my sub sub entities dictionaryItem is not loaded.
if i load only GroupItem - everything is ok.
do i something wrong ?

thanks in advance!

[EL Finer]: connection: 2013-01-23 11:13:30.539--ServerSession(945282069)--Thread(Thread[Worker-3,5,main])--client acquired: 1651928704
[EL Finer]: transaction: 2013-01-23 11:13:30.539--ClientSession(1651928704)--Thread(Thread[Worker-3,5,main])--acquire unit of work: 1297139712
[EL Finest]: query: 2013-01-23 11:13:30.54--ClientSession(1651928704)--Thread(Thread[Worker-3,5,main])--Execute query ReadAllQuery(name="loadGroupMembershipWithProfileId" referenceClass=GroupMembershipProfile sql="SELECT t1.ID, t1.GROUPITEM_ID, t1.PROFILE_ID, t0.ID, t0.DELETABLE, t0.KEYNAME, t0.KEYNAMEPREFIX FROM GROUP_ITEM t0, GROUP_PROFILE t1 WHERE ((t1.PROFILE_ID = ?) AND (t0.ID = t1.GROUPITEM_ID))")
[EL Finest]: connection: 2013-01-23 11:13:30.54--ServerSession(945282069)--Connection(1920638887)--Thread(Thread[Worker-3,5,main])--Connection acquired from connection pool [read].
[EL Finest]: connection: 2013-01-23 11:13:30.54--ServerSession(945282069)--Thread(Thread[Worker-3,5,main])--reconnecting to external connection pool
[EL Fine]: sql: 2013-01-23 11:13:30.546--ServerSession(945282069)--Connection(1992025295)--Thread(Thread[Worker-3,5,main])--SELECT t1.ID, t1.GROUPITEM_ID, t1.PROFILE_ID, t0.ID, t0.DELETABLE, t0.KEYNAME, t0.KEYNAMEPREFIX FROM GROUP_ITEM t0, GROUP_PROFILE t1 WHERE ((t1.PROFILE_ID = ?) AND (t0.ID = t1.GROUPITEM_ID))
	bind => [2]
[EL Finest]: connection: 2013-01-23 11:13:30.547--ServerSession(945282069)--Connection(1920638887)--Thread(Thread[Worker-3,5,main])--Connection released to connection pool [read].
[EL Finest]: query: 2013-01-23 11:13:30.548--ServerSession(945282069)--Thread(Thread[Worker-3,5,main])--Execute query ReadObjectQuery(name="profile" referenceClass=Profile )
[EL Finer]: transaction: 2013-01-23 11:13:30.548--UnitOfWork(1297139712)--Thread(Thread[Worker-3,5,main])--begin unit of work commit
[EL Finer]: transaction: 2013-01-23 11:13:30.548--UnitOfWork(1297139712)--Thread(Thread[Worker-3,5,main])--end unit of work commit
[EL Finer]: transaction: 2013-01-23 11:13:30.548--UnitOfWork(1297139712)--Thread(Thread[Worker-3,5,main])--resume unit of work


@Entity
@Table(name = "GROUP_PROFILE")
@NamedQueries({
	@NamedQuery(name = "loadGroupMembershipWithProfileId", query = "SELECT gmp FROM GroupMembershipProfile gmp WHERE gmp.profile.id=:profileId"),
	@NamedQuery(name = "loadGroupMembershipWithGroupId", query = "SELECT gmp FROM GroupMembershipProfile gmp WHERE gmp.groupItem.id=:groupId"),
	@NamedQuery(name = "deleteAllGroupMembershipByProfileId", query = "DELETE FROM GroupMembershipProfile a WHERE a.profile.id=:profileId")
})
public class GroupMembershipProfile extends DataObject{
	@ManyToOne(cascade = { REFRESH, MERGE }, fetch = EAGER)
	@JoinColumn(name="GROUPITEM_ID")
	@JoinFetch(INNER)
	private GroupItem groupItem;

...
}

@Entity
@Table(name = "GROUP_ITEM")
@NamedQueries({
	@NamedQuery(name = "loadAllGroupsWithPrefix", query = "SELECT a FROM GroupItem a WHERE a.keyNamePrefix=:prefix"),
	@NamedQuery(name = "findGroupItemByKey", query = "SELECT a FROM GroupItem a WHERE a.keyName=:key")
})
public class GroupItem extends AbstractKeyItem<GroupNameML> implements IKeyItem{

	@OneToMany(fetch = EAGER, cascade = ALL)
	@MapKey(name="languageCode")
	@PrivateOwned
	@JoinColumn(name="OWNER_ID", referencedColumnName="ID")
	@JoinFetch(INNER)
	private Map<String, GroupNameML> dictionaryItem = new HashMap<String, GroupNameML>();

...
}
Re: Related sub entities not loaded - EAGER ignored? [message #1005127 is a reply to message #1004481] Thu, 24 January 2013 14:25 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

It will be load in a separate query. The @JoinFetch annotation only works one level deep. To join fetch multiple levels you need to put the join fetch on the query.
In general join fetching many levels, or a OneToMany is not a good idea as you must select a lot of duplicate data. Batch fetching is normally more efficient.

See,
http://java-persistence-performance.blogspot.com/2010/08/batch-fetching-optimizing-object-graph.html

To join fetch both levels use,
@NamedQuery(name = "loadGroupMembershipWithProfileId", query = "SELECT gmp FROM GroupMembershipProfile gmp join fetch gmp.groupItem join fetch gmp.groupItem.dictionaryItem WHERE gmp.profile.id=:profileId")

(or use the "eclipselink.join-fetch" query hint)


James : Wiki : Book : Blog : Twitter
Re: Related sub entities not loaded - EAGER ignored? [message #1005172 is a reply to message #1005127] Thu, 24 January 2013 15:31 Go to previous message
Filipp A. is currently offline Filipp A.
Messages: 49
Registered: February 2010
Member
You made my day! Thank you!
Previous Topic:Eclipselink and oderby does not work on criteria fetch query
Next Topic:Eclipselink is reverting my LAZY settings
Goto Forum:
  


Current Time: Wed Sep 17 21:47:00 GMT 2014

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

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