-->
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.  [ 1 post ] 
Author Message
 Post subject: Query Performance Question re: Bi-Directional One-to-One
PostPosted: Wed Jan 17, 2007 11:19 am 
Beginner
Beginner

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

I am currently evaluating Hibernate 3.2.

I am working with a query which uses FETCH JOINS across 3 tables and returns a list of entities. I expected a single select but in fact am getting multiple selects. I would like to know if anybody has experienced similar behavior and if hibernate is working as designed. I have not come across any documentation explaining this behavior so thought I would come to the experts.

My test case was using 3 entities, with bi-directional required one-to-one relationships between the tables :

SC (1 <--> 1) AC (1 <--> 1) AP

where AC has a foreign key to SC and a foreign key to AP.

I had the following named query which retrieved AC objects and did a FETCH JOIN to load the SC and AP objects :

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


If I ran this query with 5 rows in each table, hibernate would execute 11 selects :

1. The original named query
2. 5 selects on AC where criteria was foreign key SC
3. 5 selects on AC where criteria was foreign key AP

I was expecting a single query. When I changed the relationship to uni-directional, a single query was executed and it loaded all 15 entities.

Is this expected behavior?

Any help or suggestion would be much appreciated.

Regards,
Kurt


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

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.