使用 RequestFactory & 删除 OneToMany 中的实体日本PA
我想知道使用 RequestFactory 从 GWT 内的一对多关系中删除子项的正确方法是什么。
我的 GWT 应用程序具有名为 Product 的实体,并且该产品与 Expert 具有一对多关系:
@Entity
public class Product {
...
OneToMany(mappedBy="product", orphanRemoval=true,
cascade={CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
Set<Expert> experts = new HashSet<Expert>();
...
}
@Entity(name = "EXPERT")
public class Expert {
...
@ManyToOne(optional=false)
Product product;
...
}
我有一个用户界面,您可以在其中更改以下值产品,也是一个可以添加或删除专家的窗口。添加专家很顺利,但如何删除专家呢?我必须在客户端和服务器端进行哪些管理?
我已经打开了一个正在处理的产品请求。
I would like to know what's the right way to remove a child from a one-to-many relation within GWT using the RequestFactory.
My GWT application with an Entity called Product and that product has a one-to-many relation to an Expert:
@Entity
public class Product {
...
OneToMany(mappedBy="product", orphanRemoval=true,
cascade={CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH},fetch=FetchType.EAGER)
Set<Expert> experts = new HashSet<Expert>();
...
}
@Entity(name = "EXPERT")
public class Expert {
...
@ManyToOne(optional=false)
Product product;
...
}
I have a user-interface where you can change some values of Product, but also a window where experts can be added or removed. Adding a Expert goes well, but how do I remove an expert? And what administration must I do on the client and server side?
I have already an opened productRequest going on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也回答了你的JPA问题。
根据我过去的经验,在 Hibernate 中删除父子双向关系中的子项可能非常棘手。
我通常做的是使用单向映射,即产品不包含专家集。但是您可以实现一个 getter 来获取所有使用 Hibernate 调用的专家。优点是:
您可以随时返回并在稍后阶段实现缓存或急切获取。大多数时候,它们都是不必要的过早优化。
I have answered your JPA question as well.
Base on my past experience, removing a child in parent-child bi-directional relationship in Hibernate can be very tricky.
What I usually do is use uni-directional mapping instead, i.e. Product does not hold the set of experts. But you can implement a getter to get all experts using Hibernate call. The advantages are:
You can always come back and implement caching or eager fetching at later stage. And most of the time they are unnecessary pre-mature optimization.