Question

I'm getting this:

[org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/PontoComentario].[jsp]] (http--0.0.0.0-8080-2) Servlet.service() for servlet jsp threw exception: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:149) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:195) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185) [hibernate-core-4.0.1.Final.jar:4.0.1.Final

After acessing the jsp. My EMFactory is like this:

import javax.ejb.Stateless;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.transaction.UserTransaction;

@Stateless 
public class EMFactory {

public static EntityManager getEntityManager() {

    try {
        Context ctx = new InitialContext();
        return (EntityManager) ctx.lookup("java:comp/env/PontoComentario/EntityManager");
    } catch (Exception e) {
        return null;
    }
}

public static UserTransaction getUserTransaction() {

    try {
        Context ctx = new InitialContext();
        return (UserTransaction) ctx.lookup("java:comp/UserTransaction");
    } catch (Exception e) {
        return null;
    }
}   
}

I'm not sure why i'm getting that, i was using AS 5 and it was working nice. If you need any other piece of code just ask.

This is a sad part of scriptlets that was use in the jsp:

    <%
      UsuarioDao dao = new UsuarioDao();
  List<Usuario> lista;
      if (usuarioLogado.getAdministrador()) {
        lista = dao.getListOrder("codigo");
} else {
        lista = dao.getListCond("obj.administrador = true order by obj.codigo");

... and so on.

Was it helpful?

Solution

Why don't you simply inject a reference to the EntityManager with an annotation:

@PersistenceContext EntityManager em;

And are you really accessing your SLSB from a JSP? Not from a servlet controller?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top