1. 程式人生 > >Hibernate :should be mapped with insert="false" update="false"

Hibernate :should be mapped with insert="false" update="false"

錯誤:
Repeated column in mapping for entity: com.hibernateOut.entity.Orderitem column: oid (should be mapped with insert=“false” update=“false”)

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.hibernateOut.entity.Orderitem column: oid (should be mapped with insert="false" update="false")
	at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:764)
	at org.hibernate.mapping.PersistentClass.checkPropertyColumnDuplication(PersistentClass.java:782)
	at org.hibernate.mapping.PersistentClass.checkColumnDuplication(PersistentClass.java:804)
	at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:539)
	at org.hibernate.mapping.RootClass.validate(RootClass.java:265)
	at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:329)
	at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:443)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
	at com.strurts.utli.HibernateUtils.<clinit>(HibernateUtils.java:23)
	... 25 more

原因:
這是因為在Hibernate 一對多關係新增中 重複對映實體類的列

解決方法:
在property 中加入屬性:insert=“false” update=“false”

<property name="oid" type="java.lang.Integer" column="oid" insert="false" update="false"/>