-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: JPQL Eager Fetch Plan Configuration Question
PostPosted: Thu Jan 25, 2007 7:28 pm 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
Hello All,

I am currently evaluating ORM solutions, including Hibernate 3.2 and KODO 4.1 running in Glassfish v1.

I have the following scenario where I have 2 entities with a lazy one-to-one bi-directional relationship : AC <-- AP

I have written a query to return a list of AC objects and want to fetch the related AP objects as well :

@NamedQuery(name="AC.findACListByValueWithFetchJoin3",
query="SELECT DISTINCT c FROM AC c JOIN FETCH
c.ap " + "WHERE c.value = :value")


Hibernate will fetch in a list of all of the AC and AP objects and totally resolve both ends of the relationship; however, if will run n+1 queries. It appears that the n queries are to resolve the inverse side of the relationship.

In the corresponding Kodo test, it will eventually execute the n+1 but only when the inverse relationship is accessed.

Is it possible in Hibernate to setup a fetching strategy to load all of the objects but lazily resolve the inverse relationships?

Thanks for the time.

Regards,
Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 10:25 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Are you remembering to put the constrained="true" attribute in your inverse one-to-one element? If you skip it, then the relationship cannot be proxied, and the original objects will be eagerly loaded. If you loaded the objects first, then inflated the associated objects, you wouldn't see the n queries, because they'd all be in the session cache already.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: JPQL Eager Fetch Plan Configuration Question
PostPosted: Fri Jan 26, 2007 9:30 am 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
Thanks for the reply!

I am using annotations but I think the following definition of the inverse relationship would be equivalent to specifying constrained="true" in the xml :

Code:
// AC inverse relationship
@OneToOne(mappedBy="ap", optional=false, fetch=FetchType.LAZY)
private AC ac;


It appears that all the eagerly fetched objects are inflated with the exception of the inverse relationship which is proxied and then resolved with n queries.

Regards,
Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 28, 2007 4:33 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I can't see anything in the annotations documentation that corresponds to the constrained="true" attribute. You many be out of luck. I'd experiment with many-to-one for the inverse association, but I can't see the equivalent of unique="true" in annoations.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: JPQL Eager Fetch Plan Configuration Question
PostPosted: Sat Feb 03, 2007 3:27 pm 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
Hello,

I did experiment with the @OneToMany on the inverse side and it looks like that may be a workaround for my scenario. I can eager fetch the entities on both sides of the relationship and the inverse association is fetched after on demand.

Thanks again for the replies.

Regards,
Kurt


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.