CUBA 平台使用错误Relationship that was not marked cascade PERSIST

最近练习公司的CUBA平台,在持久化实例时出现了一个错误,

During synchronization a new object was found through a relationship that was not marked cascade PERSIST

网上很多人都再说添加

cascade PERSIST 就可以了,但对于我来说没有任何作用,最后在cuba的官网上找到了解决方法

This exception occurs when you save (persist or merge) an object with a reference to another object which is new (does not exists in the database). To avoid the error, such new object should be saved in the same persistence context, i.e. in the same transaction.

For example, you have two related entities: Customer and Order, and Order can contain a reference to Customer. Then, you have an editor screen for Order with the corresponding datasource. Imagine that when you edit a new Order, you programmatically create a new instance of Customer and set it to Order’s attribute. After that, you commit the screen. DataManager on middleware receives a CommitContext with the new Order which has the new Customer as a reference. It invokes EntityManager.persist(order), commits the transaction, and here the exception occurs - the Customer is not passed to the persistence context and there is no CASCADE relationship between Order and Customer.

The solution is to pass the new Customer together with the new Order. It can be done automatically if the screen contains a datasource for Customer - all datasources are saved on screen commit. Alternatively, the new Customer instance can be added to CommitContext in a DsContext.BeforeCommitListener42.

其实很简单,就是说你要持久化的这个entity里的有一个或多个成员类,你需要在持久化这个entity之前将成员类先持久化,并且实在一个事物中,

比如

EntityManager.persist(order);

EntityManager.persist(Customer.);

本人懂的东西不多,看不到本质,希望看到的人将自己见解告知,共同进步

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值