尝试在管理界面(playframework)中编辑订单状态时出错

发布于 2024-12-06 15:26:12 字数 1503 浏览 0 评论 0原文

在我的应用程序中,我有一个类 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 cartItems .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沒落の蓅哖 2024-12-13 15:26:12

Order 类中设置 mappedBy 并将 @ManyToOne 添加到 CartItem 怎么样?

@Entity
public class Order extends Model {
    @ManyToOne
    private Customer customer;

    @OneToMany(mappedBy="order",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;

    @ManyToOne
    private Order order;

    private int quantity;
...
}

What about setting mappedBy in the Order class and adding @ManyToOne to the CartItem?

@Entity
public class Order extends Model {
    @ManyToOne
    private Customer customer;

    @OneToMany(mappedBy="order",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;

    @ManyToOne
    private Order order;

    private int quantity;
...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文