Hibernate 中自引用类的问题
我有一个模拟父/子结构的实体,这是我的休眠映射文件:
<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>
这是数据:
"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"
我的问题是,每当我尝试在视图中显示对象时,多对一关联都会生成异常:
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.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)
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)
...
注意:我使用 Hibernate、Spring 和 JSF
感谢您的帮助
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.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)
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
显然,Ajax4JSF 尝试将您的数据序列化为 Javascript,并陷入无限递归,因为您的对象图是循环的(父项指向子项,子项指向父项)。也许您需要找到一种方法从 Ajax4JSF 序列化中排除“子到父”关系。
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.
它看起来像一个无限循环。您确定您的数据不包含作为其自己子项的父项吗?它也可能是一个-> b和b-> a,或任何其他循环。
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.