多一对一关系中的冬眠无限递归错误
可能是我不了解一些内核的东西,但是希望。
首先:我正在使用动态映射实体模式(我知道这不是一种优雅的方法):
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd">
<class entity-name="UserInfo" schema="MDM_DATA" table="UserInfo">
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
<id column="user_id" name="user_id" type="long">
<generator class="identity"/>
</id>
<property column="lastName" name="lastName" type="text"/>
<property column="firstName" name="firstName" type="text"/>
<property name="lastrec" type="int" generated="insert">
<column name="lastrec" default="1" not-null="true"/>
</property>
<property name="recdateend" type="timestamp" generated="insert">
<column name="recdateend" default="CAST('01/01/3000' as timestamp)" not-null="true"/>
</property>
<property name="recdatebegin" type="timestamp" generated="insert">
<column name="recdatebegin" default="current_timestamp" not-null="true"/>
</property>
<property name="recdatenew" type="timestamp" generated="insert">
<column name="recdatenew" default="current_timestamp" not-null="true"/>
</property>
<set lazy="false" inverse="true" cascade="all" name="UserExtraParam">
<key column="user_id"/>
<one-to-many class="UserExtraParam"/>
</set>
</class>
<class entity-name="UserExtraParam" schema="MDM_DATA" table="UserExtraParam">
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
<id column="user_id" name="user_id" type="long">
<generator class="foreign">
<param name="property">UserInfo</param>
</generator>
</id>
<property column="param_value" name="param_value" type="text"/>
<property column="param_key" name="param_key" type="text"/>
<many-to-one name="UserInfo" column="user_id" lazy="proxy" insert="false" update="false" class="UserInfo" not-null="false"/>
</class>
</hibernate-mapping>
当我想通过查询接收所有数据时(类似这样):
select ent from UserInfo ent
我会遇到无限的递归错误(当我想时Hibernate尝试让Userextraparam for UserInfo):
Hibernate: select userinfo0_.user_id as user_id1_1_, userinfo0_.lastName as lastname2_1_, userinfo0_.firstName as firstnam3_1_, userinfo0_.recdatebegin as recdateb4_1_, userinfo0_.recdateend as recdatee5_1_, userinfo0_.recdatenew as recdaten6_1_, userinfo0_.lastrec as lastrec7_1_ from "MDM_DATA".UserInfo userinfo0_
Hibernate: select userextrap0_.user_id as user_id1_0_0_, userextrap0_.user_id as user_id1_0_1_, userextrap0_.param_key as param_ke2_0_1_, userextrap0_.param_value as param_va3_0_1_ from "MDM_DATA".UserExtraParam userextrap0_ where userextrap0_.user_id=?
....
(last query repeat N-over times)
如何解决?
May be I don't understand some kernel things, but hope.
First of all: I'm using dynamic-map entity mode (I know it is not an elegant approach):
<hibernate-mapping xmlns="http://www.hibernate.org/xsd/hibernate-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://www.hibernate.org/xsd/hibernate-mapping/hibernate-mapping-4.0.xsd">
<class entity-name="UserInfo" schema="MDM_DATA" table="UserInfo">
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
<id column="user_id" name="user_id" type="long">
<generator class="identity"/>
</id>
<property column="lastName" name="lastName" type="text"/>
<property column="firstName" name="firstName" type="text"/>
<property name="lastrec" type="int" generated="insert">
<column name="lastrec" default="1" not-null="true"/>
</property>
<property name="recdateend" type="timestamp" generated="insert">
<column name="recdateend" default="CAST('01/01/3000' as timestamp)" not-null="true"/>
</property>
<property name="recdatebegin" type="timestamp" generated="insert">
<column name="recdatebegin" default="current_timestamp" not-null="true"/>
</property>
<property name="recdatenew" type="timestamp" generated="insert">
<column name="recdatenew" default="current_timestamp" not-null="true"/>
</property>
<set lazy="false" inverse="true" cascade="all" name="UserExtraParam">
<key column="user_id"/>
<one-to-many class="UserExtraParam"/>
</set>
</class>
<class entity-name="UserExtraParam" schema="MDM_DATA" table="UserExtraParam">
<tuplizer entity-mode="dynamic-map" class="org.hibernate.tuple.entity.DynamicMapEntityTuplizer"/>
<id column="user_id" name="user_id" type="long">
<generator class="foreign">
<param name="property">UserInfo</param>
</generator>
</id>
<property column="param_value" name="param_value" type="text"/>
<property column="param_key" name="param_key" type="text"/>
<many-to-one name="UserInfo" column="user_id" lazy="proxy" insert="false" update="false" class="UserInfo" not-null="false"/>
</class>
</hibernate-mapping>
And when i want to receive all data by query(something like this):
select ent from UserInfo ent
I get a infinite recursive error (when i suppose hibernate try to get UserExtraParam for UserInfo):
Hibernate: select userinfo0_.user_id as user_id1_1_, userinfo0_.lastName as lastname2_1_, userinfo0_.firstName as firstnam3_1_, userinfo0_.recdatebegin as recdateb4_1_, userinfo0_.recdateend as recdatee5_1_, userinfo0_.recdatenew as recdaten6_1_, userinfo0_.lastrec as lastrec7_1_ from "MDM_DATA".UserInfo userinfo0_
Hibernate: select userextrap0_.user_id as user_id1_0_0_, userextrap0_.user_id as user_id1_0_1_, userextrap0_.param_key as param_ke2_0_1_, userextrap0_.param_value as param_va3_0_1_ from "MDM_DATA".UserExtraParam userextrap0_ where userextrap0_.user_id=?
....
(last query repeat N-over times)
How i can resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论