异常之前保存的瞬态的实例:对象引用一个未保存的瞬态的实例 - 冲洗之前保存的瞬态的实例:儿童冲洗
如何重现问题: 1. Hibernate是加载实体“家长” 。属性“child”为空 2.“父”在屏幕上呈现,然后“child”属性自动实例化。所以,我有如下图:
Parent.child != null
Parent.child.childId = null
Parent.child.childKey = ""
Parent.child.childName = ""
问题:我怎么能强迫休眠忽略更新或插入儿童实体WHEN childID的= NULL? 如果childId!= null我想创建关系。
<hibernate-mapping>
<class name="com.test.Parent"
entity-name="ParentObject" table="parent"
dynamic-insert="false" dynamic-update="true" optimistic-lock="version">
<id name="rowId" type="long">
<column name="RowID" />
<generator class="native" />
</id>
<version name="versionSequence" type="integer"
unsaved-value="null" generated="never" insert="false">
<column name="VersionSequence" />
</version>
<many-to-one name="child" entity-name="Child" fetch="select"
optimistic-lock="true" embed-xml="false" update="true" insert="false">
<column name="ChildID" />
</many-to-one>
<property name="dateCreated" type="timestamp">
<column name="DateCreated" length="0" />
</property>
<property name="dateUpdated" type="timestamp" update="false">
<column name="DateUpdated" length="0" />
</property>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="com.Child"
entity-name="Child" table="Child" dynamic-insert="false"
dynamic-update="true" optimistic-lock="version">
<id name="childId" type="long" >
<column name="ChildID" />
<generator class="native" />
</id>
<version name="versionSequence" type="integer" insert="false"
generated="never" >
<column name="VersionSequence" />
</version>
<property name="childKey" type="string" >
<column name="ChildKey" length="20" />
</property>
<property name="childName" type="string" >
<column name="ChildName" length="30" />
</property>
<property name="childNumber" type="string" >
<column name="ChildNumber" />
</property>
<property name="dateCreated" type="timestamp">
<column name="DateCreated" />
</property>
<property name="dateUpdated" type="timestamp" update="false">
<column name="DateUpdated" />
</property>
</class>
</hibernate-mapping>
很抱歉误解了你的问题。我同意axtavt。 Hibernate是做错的地方。如果你肯定,你可能会考虑拦截器,尽管我不确定他们会为此工作。 – 2011-02-09 03:14:54