“用于实体的映射中的重复列”每列只映射一次 [英] "Repeated column in mapping for entity" where each column is only mapped once
问题描述
我有一个hibernate映射文件ParcelServicePresetIds.hbm.xml:
< hibernate-mapping>
< class name =de.delife.sql.ParcelServicePresetIdstable =ParcelServicePresetIDsschema =dbocatalog =xxx>
< id name =idtype =int>
< column name =ID/>
< generator class =assigned/>
< / id>
< column name =ItemID/>
< /多对一>
< property name =itemIdcolumn =ItemIDtype =java.lang.Integer/>
< property name =intValuetype =java.lang.Integer>
< column name =intValue/>
< / property>
< / class>
< / hibernate-mapping>
运行程序时出现错误:
创建初始SessionFactory failed.org.hibernate.MappingException:实体映射中的重复列:de.sql.ParcelServicePresetIds列:ItemID(应该使用insert =false更新=false)
为什么?
我有另一个实体Others.hbm.xml:
<多对一名称=itemsBaseclass = de.sql.ItemsBasefetch =selectproperty-ref =itemId>
< column name =ItemIDunique =true/>
< /多对一>
< property name =itemIdcolumn =ItemIDtype =java.lang.Integer/>
在这个实体中它正在工作!我不明白!
有人可以解释这个区别吗?
您可能不需要在这里使用propertyRef。它可以简单地为:
<多对一名称=itemsBaseclass =de.sql.ItemsBase fetch =selectcolumn =ItemID/>
另外,您不需要 itemId $的属性声明c $ c>。
回答问题的第二部分:
insert =falseupdate =false
I have a hibernate mapping file ParcelServicePresetIds.hbm.xml:
<hibernate-mapping>
<class name="de.delife.sql.ParcelServicePresetIds" table="ParcelServicePresetIDs" schema="dbo" catalog="xxx">
<id name="id" type="int">
<column name="ID" />
<generator class="assigned" />
</id>
<many-to-one name="itemsBase" class="de.sql.ItemsBase" fetch="select" property-ref="itemId">
<column name="ItemID" />
</many-to-one>
<property name="itemId" column="ItemID" type="java.lang.Integer"/>
<property name="intValue" type="java.lang.Integer">
<column name="intValue" />
</property>
</class>
</hibernate-mapping>
When I run my program I get an error:
Initial SessionFactory creation failed.org.hibernate.MappingException: Repeated column in mapping for entity: de.sql.ParcelServicePresetIds column: ItemID (should be mapped with insert="false" update="false")
Why?
I've another entity Others.hbm.xml:
<many-to-one name="itemsBase" class="de.sql.ItemsBase" fetch="select" property-ref="itemId">
<column name="ItemID" unique="true" />
</many-to-one>
<property name="itemId" column="ItemID" type="java.lang.Integer"/>
In this entity it's working!!! I do not understand it! Can someone explain the difference?
You probably don't need to use a propertyRef here. It could simply be:
<many-to-one name="itemsBase" class="de.sql.ItemsBase" fetch="select" column="ItemID"/>
Also, you don't require the property declaration for itemId
.
To answer the second part of the question:
- Whenever you give propertyRef, you need to follow it up with a property definition.
- If it is a 'managed column', i.e. a foreign-key-reference for example; you ought to qualify the property definition with
insert="false" update="false"
- However, in most cases; you donot need a propertyRef. You can do with a simple column definition in the many-to-one section.
这篇关于“用于实体的映射中的重复列”每列只映射一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!