尝试更新对象时出现以下异常:
org.hibernate.TransientObjectException:对象引用了一个未保存的瞬态实例-在刷新之前保存该瞬态实例:......
谁能帮忙???
我要更新的对象在映射文件中将’lazy’属性设置为false。似乎hibernate状态希望我在刷新更新之前保存子对象???
编辑(添加):
<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>
应用程序处于Spring环境中。修复:在Hibernate环境中运行更新。