4 Replies Latest reply on Oct 4, 2007 3:17 PM by Daniel Celentano

    Problems using Extended Persistence Context

    Daniel Celentano Newbie

      I'm using EXTENDED Persistence Context with a SFSB, expecting that "the lifecycle of the persistence context is binded to the lifecycle of the Stateful Session Bean" but this dont work.

      I'm get org.hibernate.LazyInitializationException in the second lap, this is the same method invocation with different results. May by a Bug?

      This is my code:

      CLIENT

      public class Client
      {
      public static void main(String[] args) throws Exception
      {
      InitialContext ctx = new InitialContext();
      IProceso proceso = (IProceso) ctx.lookup("cine/ProcesoBean/remote");
      List peliculas = null;


      // lap 1

      proceso.crearDatos();
      peliculas = proceso.listarPeliculas();
      showPeliculas(peliculas);
      proceso.grabar();
      System.out.println("Lap 1 OK!");

      // lap 2
      proceso = (IProceso) ctx.lookup("cine/ProcesoBean/remote");
      peliculas = proceso.listarPeliculas();
      showPeliculas(peliculas);
      proceso.grabar();
      System.out.println("Lap 2 OK!");

      }


      SERVER


      @Stateful
      public class ProcesoBean implements IProceso{

      @PersistenceContext(type=PersistenceContextType.EXTENDED)
      private EntityManager em;


      public void crearDatos(){
      System.out.println("crearDatos");
      System.out.println("EM: " + em.hashCode());
      // make data insert on DB

      ....


      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
      public List listarPeliculas() {

      List pelis = null;
      pelis = em.createQuery("from Movie p where p.salaCompleta is false").getResultList();
      return pelis;
      }



      @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
      public void salaCompleta(Long idpelicula) {
      Movie pelicula = em.find(Movie.class, idpelicula);
      pelicula.setSalaCompleta(Boolean.TRUE);
      }


      @Remove
      public void grabar() {
      }