【发布时间】:2013-12-03 19:53:05
【问题描述】:
//MyEntity.java
@RooJavaBean
@RooToString
@RooEntity
public class MyEntity {
@PersistenceContext(unitName = "persistenceUnit")
transient EntityManager entityManager;
@NotNull
private String name;
@ElementCollection(targetClass = MyEnumType.class)
@Enumerated(EnumType.STRING)
private Set<MyEnumType> myEnumTypes = new HashSet<MyEnumType>();
public boolean isMyEnumPartOfMyEntity(MyEnumType e) {
for (MyEnumType type : myEnumTypes) {
if (type.equals(e)) {
return true;
}
}
return false;
}
}
//MyEnumType.java
public enum MyEnumType {
HI, HELLO, GREETINGS;
}
如果我打电话
myEntity.isMyEnumPartOfMyEntity(MyEnumType.HELLO)
我得到休眠延迟加载异常
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.rishi.myEnumTypes, no session or session was closed
问题是如何快速加载我的 myEnumTypes 集?
谢谢。
【问题讨论】:
标签: java spring hibernate persistence spring-roo