0 Replies Latest reply on Nov 3, 2005 2:40 PM by Leandro Sinhorini Alves

    LazyInitializationException inside JTA transaction

    Leandro Sinhorini Alves Newbie

      I'm using JBoss 4.0.3SP1 whit EJB3 and MyFaces.

      In a JSF managed bean, my application begin a JTA transaction and invoke a stateless session façade that return a entity bean. The entity bean has a lazy collection that throws org.hibernate.LazyInitializationException when I try to get it at managed bean method.

      Follow the managed bean method:

      public String consultar() throws Exception {
       ServiceLocator locator = ServiceLocator.getInstance();
       UserTransaction tx = (UserTransaction) locator.lookup( "java:comp/UserTransaction" );
       try {
       AplicacaoFacade facade = locator.lookupEJB( AplicacaoFacade.class );
       // Get informations for page
       vo = (UsuarioVO) paginaRegistros.getRowData();
       Usuario usuario = facade.getUsuarioPorId( vo.getId() );
       // Build organizations collection
       List<Long> organizacoesId = new ArrayList<Long>();
       // THROWS LAZY EXCEPTION !!!!!!
       for ( Organizacao organizacao : usuario.getOrganizacoes() ) {
       organizacoesId.add( organizacao.getId() );
       catch ( Exception e ) {
       return Constantes.OUTCOME_SUCESSO;

      The session façade uses dependency injection to get entity manager:

      public class AplicacaoFacadeBean implements AplicacaoFacade {
       @PersistenceContext EntityManager entityManager;
       public Usuario getUsuarioPorId( Long usuarioId ) {
       return entityManager.find( Usuario.class, usuarioId );

      Why is it happening? Shouldn't entity manager be open until JTA commit ou rollback?