-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: LazyInitializationException (Hibernate 3.3.2, Struts 2)
PostPosted: Sun Jan 24, 2010 9:37 pm 
Newbie

Joined: Sat Jan 09, 2010 8:41 am
Posts: 2
Can anyone explain this? Why just the second "setUsuario" doesn't gives me a LazyInitializationException (when rendering the JSP)?
Code:
   public String execute() throws Exception
   {
      // Executa código comum ás páginas
      super.execute();
      //setUsuario(base_usuario);
      
      // TODO preencher com algo - página inicial do sistema! (blog?)
      
      Session sess = HibernateUtil.getSessionFactory().getCurrentSession();      
      ArrayList<UsuariosVO> arr = (ArrayList<UsuariosVO>) sess.createQuery("from UsuariosVO").list();
      UsuariosVO usr = arr.get(0);      
      setUsuario(usr);
      
      //InitialContext ic = new InitialContext();
      //SegurancaEJBIf ejbSeguranca = (SegurancaEJBIf) ic.lookup("ejb/Seguranca");
      //UsuariosVO u = ejbSeguranca.obterUsuario(base_userCtx.getUsername());
      //setUsuario(u);
      
      return SUCCESS;
   }


super.execute():
Code:
   public String execute() throws Exception
   {
      // Contexto do usuario
      base_userCtx = UserContext.getContext();

      // Carrega os EJBs a serem usados
      InitialContext ic = new InitialContext();
      base_ejbSeguranca = (SegurancaEJBIf) ic.lookup("ejb/Seguranca");
      base_ejbNavegacao = (NavegacaoEJBIf) ic.lookup("ejb/Navegacao");

      // Nome de usuario -> Objeto do usuário
      base_usuario = base_ejbSeguranca.obterUsuario(base_userCtx.getUsername());

      // Carrega conteúdo comum ás páginas
      configuraMenuLateral(base_usuario);
      carregaMensagensAnuncio(base_usuario);

      return null;
   }


JSP that is bound to this Action:
Code:
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class="tc_content">
   <ul>
      <s:iterator value="usuario.grupos">
      <li><s:property value="nome" /></li>
      </s:iterator>
   </ul>
</div>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.