-->
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: only one HQL 'From' clause generates many SQL selects
PostPosted: Mon Apr 03, 2006 2:36 pm 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
Hi,

I use session.find("From DataSource").
I get one SQL statement to retrieve all datasource rows but then I get a different SQL select for each Institution linked to a datatource.

Do you know where it could come from ?
thank you,

Here is part of my mapping:

<class name="DataSource" table="codDataSource" mutable="false">
<id name="Id" >
<generator class="increment" />
</id>
<property name="Description" />
<property name="Code" />
<many-to-one name="Institution" column="InstitutionId"/>
</class>

<class name="StatefulEntity" table="tblStatefulEntity">
<id name="Id">
<generator class="sequence">
<param name="sequence">seqObject</param>
</generator>
</id>
<bag name="Aliases" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="StatefulEntityID" />
<one-to-many class="Alias" />
</bag>
<many-to-one name="StatefulEntityType" column="StatefulEntityTypeId"/>
</class>

<joined-subclass name="Institution" extends="StatefulEntity" table="tblInstitution">
<key column="Id"/>
<property name="Name" column="InstitutionName" />
<many-to-one name="Country" column="CountryID"/>
</joined-subclass>

<class name="Alias" table="tblAlias">
<id name="Id">
<generator class="increment" />
</id>
<many-to-one name="AliasType" column="AliasTypeID"/>
<many-to-one name="StatefulEntity" column="StatefulEntityID"/>
<many-to-one name="DataSource" column="DataSourceID"/>
<property name="Value" column="Alias"/>
</class>


Last edited by antho on Mon Apr 03, 2006 5:24 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 03, 2006 2:46 pm 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
I understood the problem explaining it.
The problem comes from the inverse="true" on the bag list.

What is the efficient way to write a bidirectional relation ?
I cant manage to execute my query in only one call.
When I execute session.find("From DataSource"),

first SQL call:
select * from CodDataSource

then many calls:
select * from Institution where id=1
select * from Institution where id=2
select * from Institution where id=3
...

I found this in the doc:
"Note: Large Hibernate bags mapped with inverse="false" are inefficient and should be avoided; Hibernate can't create, delete or update rows individually, because there is no key that may be used to identify an individual row. "

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 3:38 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
the extra selects come from the relation. I don't think it has anything to do with the 'inverse'. Please some1 correct me if I'm wrong.

If you do a hql like this: From DataSource left join fetch Institution
it will use a join to select the institutions.

You can also make the institutions lazy loaded. Then they won't be loaded at all.


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.