-->
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.  [ 22 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: A vicious Hibernate 2 rumour? true or false
PostPosted: Wed Dec 13, 2006 6:35 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Hibernate 2.1.8

Mapping documents:

see below....

Code between sessionFactory.openSession() and session.close():
n/a/

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):




I am on a hibernate 2 project and noticed that retrieving an instance of a class with the following set:


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskSet" table="mbl_task_set">
<id column="ts_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">mbl_task_set</param>
</generator>
</id>
<property name="userName" column="ts_user_name" not-null="true" length="24"/>
<property name="taskSetName" column="ts_name" not-null="true" length="40"/>
<property name="source" column="ts_source" not-null="true" length="10"/>

<set name="paramData" lazy="false" inverse="true" cascade="all">
<key column="tpd_ts_id"/>
<one-to-many class="com.blah.TaskParameterData"/>
</set>

</class>

</hibernate-mapping>



When retrieving the class with the set it Caused the class to do a loop through all above TaskParameterDatas in the set rather than doing a join.


Is this a Hibernate 2 problem that is fixed in Hibernate 3?



See output below:

Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?
Hibernate: select mbl_task0_.tpd_id as tpd_id__, mbl_task0_.tpd_id as tpd_id, mbl_task0_.tpd_ts_id as tpd_ts_id, mbl_task0_.tpd_seq_id as tpd_seq_id, mbl_task0_.tpd_data as tpd_data from mbl_task_param_data mbl_task0_ where mbl_task0_.tpd_ts_id=?

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Last edited by Joshva on Sun Dec 17, 2006 8:18 pm, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 6:58 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Surely someone has used <set><one-to-many> on Hibernate 2 before ... ???

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 8:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
In my view the proper way is to retain the collection as lasy=true and join the collection when required through a (HQL) query. This avoids possible cartesion-product issues. Most improtantly, this provides the code base with the greatest flexibility and data collection control.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 8:26 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Thanks David for the response.

Even with lazy=false I am still unsure of why Hibernate isn't doing a join. Why would it be running so many select statements?

Thanks,
Josh

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 8:43 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Joshva wrote:
Thanks David for the response.

Even with lazy=false I am still unsure of why Hibernate isn't doing a join. Why would it be running so many select statements?



Thanks,
Josh


dont remember what it is in 2 but on 3 you can say

fetch = "join"...

Why would it be running so many select statements? A: Cartesian product problem ..my guess

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 12:20 am 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Hi,

I hear what your saying about the Cartesian product. I am confused as to why it is doing a cartesian product. I have copied the exact 2 mapping files below....



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskParameterData" table="task_param_data">
<id column="tpd_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">mbl_task_param_data</param>
</generator>
</id>
<property name="taskSetId" column="tpd_ts_id" not-null="true" length="4"/>
<property name="sequenceId" column="tpd_seq_id" not-null="true" length="4"/>
<property name="data" column="tpd_data" not-null="false"/>
</class>

</hibernate-mapping>






<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskSet" table="mbl_task_set">
<id column="ts_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">task_set</param>
</generator>
</id>
<property name="userName" column="ts_user_name" not-null="true" length="24"/>
<property name="taskSetName" column="ts_name" not-null="true" length="40"/>
<property name="source" column="ts_source" not-null="true" length="10"/>

<set name="paramData" lazy="false" inverse="true" cascade="all">
<key column="tpd_ts_id"/>
<one-to-many class="com.blah.TaskParameterData"/>
</set>
</class>

</hibernate-mapping>




Any ideas?

Thanks,
Josh

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Last edited by Joshva on Fri Dec 15, 2006 2:00 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 1:36 am 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Joshva wrote:
Hi,

I hear what your saying about the Cartesian product. The question is why is it doing a cartesian product. I have copied the exact 2 mapping files below....



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskParameterData" table="task_param_data">
<id column="tpd_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">mbl_task_param_data</param>
</generator>
</id>
<property name="taskSetId" column="tpd_ts_id" not-null="true" length="4"/>
<property name="sequenceId" column="tpd_seq_id" not-null="true" length="4"/>
<property name="data" column="tpd_data" not-null="false"/>
</class>

</hibernate-mapping>






<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskSet" table="mbl_task_set">
<id column="ts_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">task_set</param>
</generator>
</id>
<property name="userName" column="ts_user_name" not-null="true" length="24"/>
<property name="taskSetName" column="ts_name" not-null="true" length="40"/>
<property name="source" column="ts_source" not-null="true" length="10"/>

<set name="paramData" lazy="false" inverse="true" cascade="all">
<key column="tpd_ts_id"/>
<one-to-many class="com.blah.TaskParameterData"/>
</set>
</class>

</hibernate-mapping>




Any ideas?

Thanks,
Josh

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 1:58 am 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Hi Scarface,

I'm a bit confused your post didn't have anything in it other than a direct quote of mine.

Thanks,
Josh

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 11:33 am 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Joshva wrote:
Hi Scarface,

I'm a bit confused your post didn't have anything in it other than a direct quote of mine.

Thanks,
Josh


Err .. I meant to say

outer join results in cartesian product

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 1:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Have a look at the online manual and see the option
Code:
outer-join="true"
.

http://www.hibernate.org/hib_docs/reference/en/html/collections.html

Please note the issues that can occur when you have more then one non-lasy collection.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 8:08 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
ok i've changed the association to below but the problem still occurs.

<set name="paramData" lazy="true" fetch="join" >
<key column="tpd_ts_id"/>
<one-to-many outer-join="false" class="com.blah.TaskParameterData"/>
</set>


Any further ideas?

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 8:52 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Joshva wrote:
ok i've changed the association to below but the problem still occurs.

<set name="paramData" lazy="true" fetch="join" >
<key column="tpd_ts_id"/>
<one-to-many outer-join="false" class="com.blah.TaskParameterData"/>
</set>


Any further ideas?


change that to

<set name="paramData" fetch="join" >
<key column="tpd_ts_id"/>
<one-to-many class="com.blah.TaskParameterData"/>
</set>

as David said be aware of the consequences when you do this for more than one collections

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 9:00 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
Unfortunately that did not solve the problem.

Are you sure it isn't the version of Hibernate we are using causing this?

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 9:04 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
Joshva wrote:
Unfortunately that did not solve the problem.

Are you sure it isn't the version of Hibernate we are using causing this?

Dude ... post ur mapping files ...

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 17, 2006 9:20 pm 
Newbie

Joined: Tue Dec 12, 2006 6:35 pm
Posts: 19
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskParameterData" table="task_param_data">
<id column="tpd_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">mbl_task_param_data</param>
</generator>
</id>
<property name="taskSetId" column="tpd_ts_id" not-null="true" length="4"/>
<property name="sequenceId" column="tpd_seq_id" not-null="true" length="4"/>
<property name="data" column="tpd_data" not-null="false"/>
</class>

</hibernate-mapping>






<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>

<class name="com.blah.TaskSet" table="mbl_task_set">
<id column="ts_id" name="id">
<generator class="com.blah.TableNextRowIdGenerator">
<param name="name">task_set</param>
</generator>
</id>
<property name="userName" column="ts_user_name" not-null="true" length="24"/>
<property name="taskSetName" column="ts_name" not-null="true" length="40"/>
<property name="source" column="ts_source" not-null="true" length="10"/>

<set name="paramData" lazy="false" inverse="true" cascade="all">
<key column="tpd_ts_id"/>
<one-to-many class="com.blah.TaskParameterData"/>
</set>
</class>

</hibernate-mapping>



The java code is:

result = getSession().find("from " + "com.blah.TaskSet");


Thanks

_________________
_________________________
http://www.joshandfriends.com.au

Dance Music | Events | DJs


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 22 posts ]  Go to page 1, 2  Next

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.