HIbernate Version 3.2.2
I am using the entity mode as dom4j. It is working fine for me for all cases except for
bidirectional mapping. When we use bidirectional mapping with
embed-xml="true", Hibernate fetches the data but on converting the data to xml string using dom4j leads to an infinite loop and
StackOverflowError occurs.
Is there any solution to this problem my mapping files are attched below
Code:
<?xml version="1.0" encoding="UTF-8"?>
[b]Child table[/b]
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.nest.shop.dbmodel">
<class entity-name="NTColumn" node="NTColumn" table="NTColumn">
<id column="Id" name="Id" node="Id" type="string">
<generator class="guid"/>
</id>
<!--property column="TableId" name="TableId" node="TableId"/-->
<property column="Name" name="Name" node="Name" type="string"/>
<property column="Type" name="Type" node="Type" type="string"/>
<property column="Description" name="Description" node="Description" type="string"/>
<property column="DataType" name="DataType" node="DataType" type="string"/>
<property column="DataSize" name="DataSize" node="DataSize" type="string"/>
<property column="DataScale" name="DataScale" node="DataScale" type="string"/>
<property column="Comment" name="Comment" node="Comment" type="string"/>
<many-to-one column="TableId" entity-name="NTTable"
name="myTable" embed-xml="true" node="NTTable"/>
</class>
</hibernate-mapping>
[b]Parent Table[/b]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.test.dbmodel">
<class entity-name="NTTable" node="NTTable" table="NTTable">
<id column="Id" name="Id" node="Id" type="string">
<generator class="guid"/>
</id>
<property column="Name" name="Name" node="Name" type="string"/>
<property column="Type" name="Type" node="Type" type="string"/>
<property column="Description" name="Description" node="Description" type="string"/>
<property column="Comment" name="Comment" node="Comment" type="string"/>
<property column="History" name="History" node="History" type="string"/>
<property column="Boundary" name="Boundary" node="Boundary" type="string"/>
<property column="Log" name="Log" node="Log" type="string"/>
<property column="Cache" name="Cache" node="Cache" type="string"/>
<property column="Notify" name="Notify" node="Notify" type="string"/>
<property column="Identifier" name="Identifier" node="Identifier" type="string"/>
<set name="columnSet" embed-xml="true" node="Columns" lazy="false" inverse="false">
<key column="tableId"/>
<one-to-many entity-name="NTColumn" embed-xml="true"/>
</set>
</class>
</hibernate-mapping>
Code:
List<Element> l =session.createQuery("from NTColumn" +
" where Id=1").list();
Document doc = DocumentHelper.createDocument();
Element root = doc.addElement("Root");
doc.setRootElement(root);
for (Element nTTable : l) {
nTTable.setParent(null);
doc.getRootElement().add(nTTable);
}
[b]doc.asXML()// Here causes the error StackOverflow[/b]
[/b]