[jboss-jira] [JBoss JIRA] Commented: (EJBTHREE-340) LazyInitializationException inside JTA transaction
Emmanuel Bernard (JIRA)
jira-events at lists.jboss.org
Tue Feb 13 20:45:31 EST 2007
[ http://jira.jboss.com/jira/browse/EJBTHREE-340?page=comments#action_12353030 ]
Emmanuel Bernard commented on EJBTHREE-340:
-------------------------------------------
local or remote bean?
> LazyInitializationException inside JTA transaction
> --------------------------------------------------
>
> Key: EJBTHREE-340
> URL: http://jira.jboss.com/jira/browse/EJBTHREE-340
> Project: EJB 3.0
> Issue Type: Bug
> Affects Versions: EJB 3.0 RC3
> Environment: JBoss 4.0.3 SP 1 + EJB 3.0 RC3
> Reporter: Leandro Sinhorini Alves
>
> I'm not sure if it's a bug, but I looked for a answer at the specfication and at JBoss EJB3 forum.
> 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" );
> tx.begin();
> 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() );
> }
> tx.commit();
> }
> catch ( Exception e ) {
> tx.rollback();
> }
> return Constantes.OUTCOME_SUCESSO;
> }
> The session façade uses dependency injection to get entity manager:
> Code:
> @Stateless
> public class AplicacaoFacadeBean implements AplicacaoFacade {
> @PersistenceContext EntityManager entityManager;
> public Usuario getUsuarioPorId( Long usuarioId ) {
> return entityManager.find( Usuario.class, usuarioId );
> }
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list