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>