尝试在管理界面(playframework)中编辑订单状态时出错
在我的应用程序中,我有一个类 Order
,其中包含 cartItem
的集合。订单可以具有状态 'pending' 、'confirmed'
ETC。 客户下订单后,订单状态为“已确认”。由于客户提供了错误的付款信息,管理员决定将订单状态更改为“待处理”。使用 CRUD/admin
界面,我选择了订单条目并尝试编辑状态字段。这导致了以下错误。
PersistenceException occured : org.hibernate.HibernateException:
A collection with
cascade="all-delete-orphan" was no longer referenced
by the owning entity instance: models.Order.cartItems
页面上显示的错误是:
In {module:crud}/app/controllers/CRUD.java (around line 100)
96: } catch (TemplateNotFoundException e) {
97: render("CRUD/show.html", type, object);
98: }
99: }
100: object._save();//Here error marked in red
101: flash.success(Messages.get("crud.saved", type.modelName));
102: if (params.get("_save") != null) {
103: redirect(request.controller + ".list");
104: }
105: redirect(request.controller + ".show", object._key());
106: }
我的应用程序中的模型是;
@Entity
public class Order extends Model {
@ManyToOne
private Customer customer;
@OneToMany( cascade=CascadeType.ALL,orphanRemoval=true)
private Set<CartItem> cartItems;
private String status;
...
}
@Entity
public class CartItem extends Model implements Comparable<CartItem>{
@OneToOne
private Product product;
private int quantity;
...
}
我真的不明白为什么会发生这种情况。更改字段的值如何导致这种情况?我应该怎么做才能避免这个错误?我需要管理员能够编辑此字段。
如果有人可以提出解决方案,那就太好了。
In my app ,I have a class Order
that contains a collection of cartItem
s .The Order can have status 'pending' ,'confirmed'
etc.
After the customer placed the order,it has a status 'confirmed'.Since wrong payment info was provided by customer,the admin decides to change the status of Order to 'pending'.Using the CRUD/admin
interface ,I selected the Order entry and tried to edit the status field.This caused the following error.
PersistenceException occured : org.hibernate.HibernateException:
A collection with
cascade="all-delete-orphan" was no longer referenced
by the owning entity instance: models.Order.cartItems
The error shown on page is :
In {module:crud}/app/controllers/CRUD.java (around line 100)
96: } catch (TemplateNotFoundException e) {
97: render("CRUD/show.html", type, object);
98: }
99: }
100: object._save();//Here error marked in red
101: flash.success(Messages.get("crud.saved", type.modelName));
102: if (params.get("_save") != null) {
103: redirect(request.controller + ".list");
104: }
105: redirect(request.controller + ".show", object._key());
106: }
The models in my app are;
@Entity
public class Order extends Model {
@ManyToOne
private Customer customer;
@OneToMany( cascade=CascadeType.ALL,orphanRemoval=true)
private Set<CartItem> cartItems;
private String status;
...
}
@Entity
public class CartItem extends Model implements Comparable<CartItem>{
@OneToOne
private Product product;
private int quantity;
...
}
I don't really understand why this happened.How can changing the value of a field cause this? What should I do to avoid this error? I need the admin to be able to edit this field..
If anyone can suggest a solution,it would be nice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
Order
类中设置mappedBy
并将@ManyToOne
添加到CartItem
怎么样?What about setting
mappedBy
in theOrder
class and adding@ManyToOne
to theCartItem
?