[jboss-user] [EJB/JBoss] - Problems using Extended Persistence Context

daniel.celentano do-not-reply at jboss.com
Thu Oct 4 09:59:22 EDT 2007


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() {
        }

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4091530#4091530

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4091530



More information about the jboss-user mailing list