-->
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: generated 4 sql per row
PostPosted: Wed Jul 27, 2005 7:54 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Name and version of the database you are using:

I have 5 tables one parent table A, children tables: B, C, D, E. I used discreminator in the class A to distingusih the actual type of the data (child B, C, D or E). However, when I make a hql query, I found there are 4 sql generated every row I retrieved.

For example:

hql:

from A as a where A.type = 'B'


sql gerneated:

select * top 20 from A a, B b where (a.id=b.id )

select * from B where b.id = ?
select * from C where c.id = ?
select * from D where d.id = ?
select * from E where e.id = ?


As above example, there will be 80 sql generated to retrieve 20 recrods.

The performance of the query is extremely bad and I would like to know if it is possible in hibernate to execute 1 sql to the database to map to multiple rows?




Thanks a lot!

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject: Re: generated 4 sql per row
PostPosted: Wed Jul 27, 2005 9:36 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Edmond wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.1

Name and version of the database you are using:

I have 5 tables one parent table A, children tables: B, C, D, E. I used discreminator in the class A to distingusih the actual type of the data (child B, C, D or E). However, when I make a hql query, I found there are 4 sql generated every row I retrieved.

For example:

hql:

from A as a where A.type = 'B'


sql gerneated:

select * top 20 from A a, B b where (a.id=b.id )

select * from B where b.id = ?
select * from C where c.id = ?
select * from D where d.id = ?
select * from E where e.id = ?

As above example, there will be 80 sql generated to retrieve 20 recrods.

The performance of the query is extremely bad and I would like to know if it is possible in hibernate to execute 1 sql to the database to map to multiple rows?

Thanks a lot!


http://www.hibernate.org/ForumMailingli ... AskForHelp

Can you at least include your mapping files so that we can get a better idea of what you're doing ?


Top
 Profile  
 
 Post subject: Re: generated 4 sql per row
PostPosted: Wed Jul 27, 2005 12:07 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Edmond wrote:
For example:

hql:

from A as a where A.type = 'B'


Already tried to select the B-objects as B-objects instead of selection the A-objects with type 'B'?

Code:
select b from B as b


Best regards
Sven


Top
 Profile  
 
 Post subject: Re: generated 4 sql per row
PostPosted: Wed Jul 27, 2005 9:33 pm 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
sven wrote:
Edmond wrote:
For example:

hql:

from A as a where A.type = 'B'


Already tried to select the B-objects as B-objects instead of selection the A-objects with type 'B'?

Code:
select b from B as b


Best regards
Sven



May be I didn't describe my problem clear enough.

I have some condition needs to use the attribute in the parent table therefore, I need to use

Quote:
from A as a where A.type = 'B'



because in the where clause I will use the attribute of A.

For example,

Quote:

from A as a where A.type = 'B'
where a.name = 'pre%'




thanks for your suggestion!

best regards

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject: Re: generated 4 sql per row
PostPosted: Wed Jul 27, 2005 10:51 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Edmond wrote:

May be I didn't describe my problem clear enough.

best regards


Maybe if you'd follow the guidelines and include the necessary information, YOUR MAPPING FILE(s), we would better understand what you're asking.


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.