【发布时间】:2009-06-25 16:33:27
【问题描述】:
当我尝试更新对象时出现以下异常:
org.hibernate.TransientObjectException:对象引用了一个未保存的瞬态实例 - 在刷新之前保存瞬态实例:......
谁能帮忙???
我尝试更新的对象在映射文件中将“lazy”属性设置为 false。似乎休眠希望我在刷新更新之前保存子对象???
编辑(添加):
<hibernate-mapping>
<class name="utils.message.Message" table="messages">
<id name="id" column="message_id">
<generator class="native" />
</id>
<property name="message_text" column="message_text" />
<property name="message_file" column="message_file" />
<property name="is_active" column="is_active" type="boolean"/>
<property name="is_global" column="is_global" type="boolean"/>
<property name="start" column="start" type="java.util.Date"/>
<property name="end" column="end" type="java.util.Date"/>
<property name="last_updated" column="last_updated" type="java.util.Date"/>
<many-to-one name="last_updated_by" class="utils.user.User" column="last_updated_by" lazy="false"/>
<many-to-one name="healthDepartment" class="utils.healthdepartment.HealthDepartment" column="health_department_id" lazy="false"/>
</class>
</hibernate-mapping>
【问题讨论】:
-
似乎在映射文件中使用级联属性可以解决我的问题??只是不确定哪种风格适合我。 (虽然我认为只使用 delete-orphan 将是我需要的)。从新手的角度理解 hibernate 文档可能有点困难。
-
你能发布你的hibhernate映射文件或注释的相关部分吗?