简体   繁体   English

Hibernate oneToMany - object 引用未保存的瞬态实例

[英]Hibernate oneToMany - object references an unsaved transient instance

I have a table with a oneToMany relation:我有一张具有 oneToMany 关系的表:

<hibernate-mapping>
    <class name="com.al6.jtob.data.Lsell" table="LSELL" >
    ...
       <many-to-one name="stock" class="com.al6.jtob.data.Stock" insert="false" update="false">
          <column name="IDITEM" />
          <column name="IDWAREHOUSE" />
       </many-to-one>
    ...
    </class>
</hibernate-mapping>

The StockID is composed by (IDITEM, IDWAREHOUSE). StockID 由 (IDITEM, IDWAREHOUSE) 组成。

It works well when I load existing LSELL objects.当我加载现有的 LSELL 对象时,它运行良好。 But when I create a new LSELL object, I have this error:但是当我创建一个新的 LSELL object 时,我有这个错误:

Caused by: javax.ejb.EJBException: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.al6.jtob.data.Stock

I don't want to update or save any new "stock" into database, it's just a readonly data.我不想更新或将任何新的“库存”保存到数据库中,它只是一个只读数据。 All the stock data are complete and suffisant.所有的库存数据都是完整和充足的。 The goal is just to get the "stock" of the "Lsell" when I display a "Lsell".目标只是在我显示“Lsell”时获得“Lsell”的“库存”。

You forget to declare CascadeType in relational mapping.您忘记在关系映射中声明CascadeType you have to put cascade=all in mapping tag because CascadeType propagates entity transitions from Parent to Child.您必须将cascade=all放在映射标记中,因为CascadeType将实体转换从父级传播到子级。 For example, if you persist parent entity the referenced entities also get persisted before flushing.例如,如果您持久化父实体,则引用的实体也会在刷新之前持久化。

<one-to-many name="lsell" class="com.al6.jtob.data.Lsell" cascade="all">
   ...
</one-to-many>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对象引用了Hibernate 4.3中未保存的瞬态实例 - object references an unsaved transient instance in Hibernate 4.3 Hibernate“对象引用未保存的瞬态实例” - Hibernate “object references an unsaved transient instance” 休眠“对象引用了未保存的瞬态实例”的问题 - Hibernate “object references an unsaved transient instance” Problem Hibernate @ManyToOne映射:对象引用一个未保存的瞬态实例 - Hibernate @ManyToOne mapping: object references an unsaved transient instance Hibernate对象引用具有一对多关系的未保存的瞬态实例 - Hibernate object references an unsaved transient instance with one to many relationship Hibernate @Version注释和对象引用未保存的瞬态实例 - Hibernate @Version annotation and object references an unsaved transient instance org.hibernate.TransientObjectException: 对象引用了一个未保存的瞬态实例 - org.hibernate.TransientObjectException: object references an unsaved transient instance 使用 Hibernate 保存 object object 引用未保存的瞬态实例 在刷新之前保存瞬态实例 - save the object using Hibernate object references an unsaved transient instance save the transient instance before flushing 对象引用了一个未保存的临时实例-使用休眠空间在刷新之前保存该临时实例 - object references an unsaved transient instance - save the transient instance before flushing using hibernate spatial 休眠:对象引用了一个未保存的瞬态实例-在刷新之前保存该瞬态实例 - Hibernate : object references an unsaved transient instance - save the transient instance before flushing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM