我需要更新我的entity
。我使用Hibernatee对话,这意味着我们已经在会话缓存中有entity
。
public void handle(Request request, Session session) {
MyEntity updatedEntity = request.getEntity();
session.merge(updatedEntity); //rewrite all lazy collections
}
因此,我发送对象到客户端,客户端充满了对象,并将其发送回来进行更新。
什么问题:
懒惰的集合都不会被发送到客户端。其结果是,如果延迟集合一直没有空,比将在session.merge(updatedEntity)
字符串被重写
这是因为客户知道这些藏品一无所知元素
问:
如何以正确的方式合并entity
?意味着不重写懒惰的集合。
编辑:(我如何用我的收藏工作)
public class MyEntity {
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
@JoinColumn(name = "entity_id")
private List<AnotherEntity> anotherEntities;
public void setAnotherEntities(List<AnotherEntity> anotherEntities) {
// we must work with the same instance of list (again, because of orphanRemoval)
this.anotherEntities.clear();
this.anotherEntities.addAll(anotherEntities);
}
}
在您的问题中,您没有显示/描述我们如何使用收藏。如果您不修改集合,则不能有合并问题。如果收集被修改,请指定何时以及如何执行此操作。 – mvb13
@ mvb13,我在编辑部分确定你的问题吗?如果没有 - 请告诉我,欢迎您 –
您是否尝试强制使用Hibernate.initialize(myEntity.getAnotherEntities())向客户端发送惰性集合的初始化; ? – zenbeni