开发者

Problems with Self-referencing classes in Hibernate

I have an entity that models the parent/child structure, here is my hibernate mapping file:

<hibernate-mapping>
    <class name="myPackage.entities.Module"  table="MODULE">
        <id name="idModule" type="int">
            <column name="ID_MODULE" precision="6" scale="0" />
            <generator class="sequence">
                <param name="sequence">S_MODULE</param>
            </generator>
        </id>
        <property generated="never" lazy="false" name="nomModule"
            type="string">
            <column length="30" name="NOM_MODULE" />
        </property>
        ...
        <!-----------------Childs------------------------->         
        <set fetch="select" inverse="true" lazy="false" name="subModules"
            sort="unsorted" table="MODULE">
            <key>
                <column name="MOD_ID_MODULE" />
            </key>
            <one-to-many class="myPackage.entities.Module" />
        </set>
        <!-----------------parent------------------------->

        <many-to-one class="myPackage.entities.Module" name="parentModule">
            <column name="MOD_ID_MODULE"  />
        </many-to-one>

    </class>
</hibernate-mapping>

here is the data:

"ID_MODULE" "ID_APPLICATION" "MOD_ID_MODULE"(parent)  ...
"12"             "2"             "10"            
"10"             "2"             "3"     
"14"             "2"             "12"   
"1"                  "1"              ""    
"2"                  "1"             "1"    
"3"                  "2"             "" 
"4"                  "2"             "3"    
"13"             "2"             "4"    
"6"                  "1"             "2"    

My problem is that the association many-to-one generates exception whenever I try to display the object in the view:

javax.servlet.ServletException: L'exécution de la servlet a lancé une exception
    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
    org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

cause mère

java.lang.StackOverflowError
    java.lang.Exception.<init>(Exception.java:77)
    java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:54)
    sun.reflect.GeneratedMethodAccessor150.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:1773)
    org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1132)
    org.apache.commons.beanutils.PropertyUtilsBean.getNestedProperty(PropertyUtilsBean.java:686)
    org.apache.commons.beanutils.PropertyUtilsBean.getProperty(PropertyUtilsBean.java:715)
    org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:290)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:126)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToSt开发者_StackOverflowream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:83)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:83)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:174)
    org.ajax4jsf.javascript.ScriptUtils.writeScriptToStream(ScriptUtils.java:83)
...

Note: I use Hibernate, Spring and JSF

Thanks for your helps


It clearly looks like Ajax4JSF tries to serialize your data into Javascript and falls into infinite recursion because your object graph is cyclic (parent points to child, child points to parent). Perhaps you need to find a way to exclude "child to parent" relationship from Ajax4JSF serialization.


It looks like an infinite loop. Are you sure your data does not contain a parent that is its own child? It could also be a -> b and b -> a, or any other cycle.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜