-->
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: Infinite loop?
PostPosted: Mon Nov 13, 2006 3:49 am 
Newbie

Joined: Mon Nov 13, 2006 3:40 am
Posts: 3
Hi,

I'm still fairly new to hibernate but I can't seem to find the answer to this question on the forum / google.

Is it possible to set the maximum depth of objects returned in a relation and what does Hibernate do to stop an infinite loop situation? I have seen the max_fetch_depth property which can be set but it doesn't seem to do anything.

I have a one-to-many relationship in my data model and while performing a query to find all of the parent entries hibernate appears to load all child entries, their child entries and so on.

Eventually this causes a StackOverflowError. Since the database only holds about 10 rows across all 5 tables I am drawn to believe that somewhere there is an infinite loop.

Any help with this would be much appreciated.

I am using MySQL 5

Niall


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 12:55 pm 
Regular
Regular

Joined: Tue Feb 24, 2004 11:42 am
Posts: 56
can you post your mapping file and what your code


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 13, 2006 6:28 pm 
Newbie

Joined: Mon Jul 24, 2006 3:21 pm
Posts: 14
Is it possible in your situation to use Hibernate's lazy instantiation features. This is how I'm stopping Hibernate from running into the stack overflow problem.

As far as an infinite loop is concerned... I don't think it is possible in Hibernate. Once Hibernate loads an object, if another object refers to it, it won't be re-loaded. The worst case scenario is that Hibernate would load every object in your DB, then stop. Most likely you would have a stack overflow LONG before this happens (assuming your DB isn't only a handful or records).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 5:14 pm 
Newbie

Joined: Mon Nov 13, 2006 3:40 am
Posts: 3
I'm currently using Hibernate's lazy instantiation features.

After some more debugging it seems that rather than hibernate causing a recursive loop it is infact the Xfire API I'm using. Xfire serialises the object data to XML for use in an XML web service. The problem is it seems to be trying to load all of the object data much in the same way I though hibernate was.

Is there a way to sever ties and stop any more loading once a query has been executed?

These the two Hibernate mappings which seem to be causing the problem:

BitImp.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.tagmybits.bits.model.BitImp" table="Bits" lazy="true">

   <id name="ID" column="ID" type="long">
      <generator class="increment"/>
   </id>

   <property name="content" column="Content" type="text" />
   <property name="creationDate" column="CreationDate" type="timestamp" />
   <property name="lastUpdatedDate" column="LastUpdatedDate" type="timestamp" />
   <property name="title" column="Title" type="string" />
   <property name="translator" column="Translator" type="integer" />

   <many-to-one name="creator" column="Creator" class="com.tagmybits.bits.auth.UserImp" lazy="proxy"/>
   <many-to-one name="lastUpdator" column="LastUpdator" class="com.tagmybits.bits.auth.UserImp" lazy="proxy"/>

   <set name="tags" table="Tags" inverse="true" cascade="all-delete-orphan" lazy="true"> 
      <key column="Bit"/> 
      <one-to-many class="com.tagmybits.bits.model.TagImp" not-found="exception"/>
   </set>

</class>
</hibernate-mapping>


TagImp.hbm.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.tagmybits.bits.model.TagImp" table="Tags" lazy="true">

   <id name="ID" column="ID" type="long">
      <generator class="increment"/>
   </id>

   <property name="content" column="Content" type="string"/>

   <many-to-one name="creator" column="Creator" class="com.tagmybits.bits.auth.UserImp" lazy="proxy"/>

   <many-to-one name="bit" column="Bit" class="com.tagmybits.bits.model.BitImp" lazy="proxy"/>

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 21, 2006 6:18 pm 
Newbie

Joined: Mon Nov 13, 2006 3:40 am
Posts: 3
I just stumbled upon an xfire forum with the answer to my question. Aparently it is possible to stop certain properties of an object being loaded from the xfire end by specifying Aegis bindings manually.

Here's the forum entry:

http://www.nabble.com/XFire-%2B-Hiberna ... l#a4264761


Thanks anyway,

Niall


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.