假设我正在尝试使用宁静的界面列出所有产品。
@XmlRootElement
public class Product implements Serializable {
//products attributes defined here
@OneToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="product")
private Set<ProductUser> productUsers= new HashSet<ProductUser>();
}
当我尝试在产品上调用 find.All 时,它甚至试图获取 ProductUsers 并引发异常
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role, productUsers, no session or session was closed
我不想在我的 rest xml 输出中包含产品用户。如何有选择地选择 xml 中包含的内容?
我使用 REST-Easy、JBoss AS7、JPA 和 Hibernate 作为实现。我的 EJB 3.1 方法公开为 Restful 服务。
感谢你的帮助!