-->
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.  [ 3 posts ] 
Author Message
 Post subject: Control how "joins" happen
PostPosted: Tue Jul 17, 2007 4:28 am 
Newbie

Joined: Tue Jul 17, 2007 4:12 am
Posts: 3
Hello,

I have a table (I will call it T here) and a view (=V) that need to be joined for fetching some data. The class that is stored in the table T contains a list that has the references to the elements in V.

The view V is very big and REALLY slow. When Hibernate fetches the data, the following SQL is performed:

select ... from T, V WHERE T.id = V.id(+) and T.id = ?

Problem: this takes forever. If it would select the id in the view and THEN join, the query would be quick:

select ... from T, V WHERE T.id = V.id(+) and V.id = ?

I have tried to give Hibernate hints to do this:

* I tried to set "inverse" in the mapping file, but it didn't change the query
* I tried to set lazy=true on the collection and fetch="select" to tell Hibernate to use multiple statements (which, even if it causes 12 statements instead of one would be lightyears faster than doing the huge join above) and then tell Hibernate to load the collection (using Hibernate.initialize(myObject.myCollection)) - but this didn't initialize the attributes. Using lazy="false" and fetch="select" didn't change anything (why not?)

Any idea of what I'm doing wrong or how to tackle this issue?

Thank you for any pointers in this regard.

Version: Hibernate 3.1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 5:22 am 
Senior
Senior

Joined: Thu May 17, 2007 2:31 am
Posts: 194
Location: Sri Lanka
Hi

try using Criteria

sess.createCriteria(T.class,"t")
.createCriteria("V","v")
.add( Restrictions.eq("t.id",value)).list();

Amila

(Don't forget to rate if helps)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 17, 2007 8:03 am 
Newbie

Joined: Tue Jul 17, 2007 4:12 am
Posts: 3
amila733 wrote:
sess.createCriteria(T.class,"t")
.createCriteria("V","v")
.add( Restrictions.eq("t.id",value)).list();


hmm, this leads to the same query (and I think it should). I tried to change it to:

sess.createCriteria(T.class,"t")
.createCriteria("V","v")
.add( Restrictions.eq("v.id",value)).list();

but that doesn't quite work. The "value" that you provide here should actually come out of the "mother" table. So there is a table T and a view V and an association (that is modeled as a table). I would need to say: Get entity X from T where T = myValue and all the entities Y from V where V.kdnr = T.kdnr. Then Hibernate joins as posted in the first paragraph, but it should try to join "the other way around" (because that would be faster). Any ideas on how to do that?

My workaround so far: Select the entity X from T and load all entities Y with a criteria -> 2 selects.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.