在将我的酒店实体持久化到后端(mysql)后,任何下一个前端客户端调用刷新设备列表(酒店中的集合)都会遇到此错误(即使我标记要收集的集合急切):
无法懒惰地初始化集合,没有会话或会话 已关闭
前端的托管bean(使用JSF):
public void save() {
hotel.setHotelUser(loginBean.getLoggedInUser());
hotel = hopAccess.persistHotel(hotel);
addMessage("Hotel saved!");
}
实体:
@Entity
@Table(name = "hotel")
public class Hotel {
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "con_hotel_equipment", joinColumns = {
@JoinColumn(name = "id_hotel", nullable = false, updatable = false) },
inverseJoinColumns = { @JoinColumn(name = "id_lookup",
nullable = false, updatable = false) })
private Set<LookUp> equipments = new HashSet<LookUp>();
服务:
@Override
@Transactional(value = "transactionManagerHop", propagation = Propagation.REQUIRES_NEW)
public Hotel persistHotel(Hotel hotel) {
Hotel entity = emHop.merge(hotel);
addToCache(entity);
return entity;
}
答案 0 :(得分:0)
在刷新您需要确保附加的实体之前,很可能实体已经脱离了持久化上下文(例如,使用entityManager.findById()或等效物)