我尝试更新对象时收到以下异常:
org.hibernate.TransientObjectException:object引用未保存的瞬态实例 - 在刷新之前保存瞬态实例:......
谁能帮忙???
我尝试更新的对象在映射文件中将"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>
Run Code Online (Sandbox Code Playgroud)
cli*_*ers 17
保存引用另一个临时对象的对象(意味着它具有"默认"标识符值,通常为null)然后刷新会话时,会发生TransientObjectException.当您创建新对象的整个图形但未明确保存所有对象时,通常会发生这种情况.有两种方法可以解决这个问题:
我建议从Hibernate文档中阅读整章,以充分理解瞬态,持久和分离的术语:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/objectstate.html
归档时间: |
|
查看次数: |
24012 次 |
最近记录: |