org.hibernate.LazyInitializationException
a7724172 Jul 31, 2013 1:03 AMi I spend a lot of timeWorking on this problem but fail please help me
The environment is jboss 7.1 ,use the jboss7.1 jar
I am in accordance with the resteasy-jaxrs-3.0.1 user guid
Below is my configuration
web.xml
<context-param>
<param-name>resteasy.jndi.resources</param-name>
<param-value>ejb:/JbossRestTest/ModelsFacadeREST!com.bjgoodwill.hip.ets.service.IModlesFacade?stateful</param-value>
</context-param>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
my service code
@Stateful
public class ModelsFacadeREST extends AbstractFacade<Models> implements IModlesFacade{
@PersistenceContext(unitName = "PU2")
private EntityManager em;
public ModelsFacadeREST() {
super(Models.class);
}
@Override
protected EntityManager getEntityManager() {
return em;
}
}
@Remote
@Path("/com.bjgoodwill.hip.ets.models")
public interface IModlesFacade {
@GET
@Produces({"application/xml", "application/json"})
public List<Models> findAll();
}
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public List<T> findAll() {
javax.persistence.criteria.CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
cq.select(cq.from(entityClass));
return getEntityManager().createQuery(cq).getResultList();
}
}
@Entity
@Table(name = "et_models")
@XmlRootElement
public class Models implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "model_name")
private String modelName;
.....................................................
@OneToMany(mappedBy = "modelName",fetch=FetchType.EAGER)
@XmlElement(name="codingSchemesList")
private List<CodingSchemes> codingSchemesList;
public Models() {
}
public Models(String modelName) {
this.modelName = modelName;
}
when i visiite http://127.0.0.1:8080/JbossRestTest/com.bjgoodwill.hip.ets.models
it Submitted to the wrong
HTTP Status 500 - org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.bjgoodwill.hip.ets.CodingSchemes.versionsList, no session or session was closed
I don't understand the reasons and how handle this probelm.thanks you can eamil me wfkjzyxy_001@163.com thanks very much thanks