-->
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.  [ 4 posts ] 
Author Message
 Post subject: LazyInitializationException
PostPosted: Tue Aug 09, 2005 12:24 pm 
Newbie

Joined: Fri Aug 05, 2005 1:22 pm
Posts: 3
Hi,
I'm using HIbernate 3 with Spring... my Spring's XML is it:



Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
   
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="configLocation">
          <value>hibernate.cfg.xml</value>
      </property>
     
   </bean>
   <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
      <property name="sessionFactory">
         <ref local="sessionFactory"/>
      </property>
   </bean>
   <bean id="eventoDAO" class="br.gov.pa.tj.evento.dao.EventoDAOImpl">
      <property name="sessionFactory">
         <ref local="sessionFactory"/>
      </property>
   </bean>
   <bean id="eventoFacade" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
      <property name="transactionManager">
         <ref local="transactionManager"/>
      </property>
      <property name="target">
         <ref local="eventoFacadeTarget"/>
      </property>
      <property name="transactionAttributes">
         <props>
            <prop key="inserir*">PROPAGATION_REQUIRED</prop>
            <prop key="alterar*">PROPAGATION_REQUIRED</prop>
            <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
         </props>
      </property>
   </bean>
   <bean id="eventoFacadeTarget" class="br.gov.pa.tj.evento.facade.EventoFacadeImpl">
      <property name="eventoDAO">
         <ref local="eventoDAO"/>
      </property>
   </bean>
</beans>


With this, my method insert functions:
Code:
public class EventoFacadeImplTest extends TestCase {
   private ApplicationContext ctx;
   private EventoFacade efacade;
   private Evento evento;

   protected void setUp() throws Exception {
      String[] paths = { "spring-hibernate.xml" };
      ctx = new ClassPathXmlApplicationContext(paths);
      efacade = (EventoFacade) ctx.getBean("eventoFacade");
   }

   protected void tearDown() throws Exception {
      evento = null;
      efacade = null;
   }

   public void testInserir() throws Exception{
      evento = new Evento();
      evento.setComponente("componente");
      evento.setDescricao("descricao");
      evento.setIcone("icone");
     
      evento = (Evento) efacade.inserir(evento);
     
      assertTrue(evento.getId()!=null);
   }



But in my method update occur an exception LazyInitializationException:

Method update:
Code:

   public void testUpdate() throws Exception {
      evento = (Evento) efacade.selecionar(new Integer(4));
      evento.setComponente("novo componente");
     
      evento = (Evento) efacade.alterar(evento);
     
   }


Exception:

Code:
09/08/2005 10:32:06 org.hibernate.LazyInitializationException <init>
SEVERE: could not initialize proxy - the owning Session was closed
org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
   at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
   at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
   at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
   at br.gov.pa.tj.evento.classe.Evento$$EnhancerByCGLIB$$a0abedcd.setComponente(<generated>)
   at br.gov.pa.tj.evento.testes.EventoFacadeImplTest.testUpdate(EventoFacadeImplTest.java:52)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


My Bean:
Code:
package br.gov.pa.tj.evento.classe;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
/**
* @hibernate.class
* table = "ARREVENTO"
* */
public class Evento implements Serializable {

   private static final long serialVersionUID = 1L;
   private Integer id;
   private String descricao;
   private String componente;
   private String icone;

   /**
    * @hibernate.property
    * */
   public String getComponente() {
      return componente;
   }

   /**
    * @hibernate.property
    * column = "DEEVENTO"
    * */
   public String getDescricao() {
      return descricao;
   }

   /**
    * @hibernate.property
    * */
   public String getIcone() {
      return icone;
   }
   /**
    * @hibernate.id
    * generator-class = "native"
    * column = "CDEVENTO"
    * */
   public Integer getId() {
      return id;
   }

   public void setComponente(String componente) {
      this.componente = componente;
   }

   public void setDescricao(String descricao) {
      this.descricao = descricao;
   }

   public void setIcone(String icone) {
      this.icone = icone;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public boolean equals(Object o) {
      if (!(o instanceof Evento)) {
         return false;
      }
      Evento rhs = (Evento) o;
      return new EqualsBuilder().appendSuper(super.equals(o)).append(id,
            rhs.id).isEquals();
   }

}



Someone can help me??


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 12:46 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
Try calling theSession.lock (evento, LockMode.NONE) before your update method.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 12:57 pm 
Newbie

Joined: Fri Aug 05, 2005 1:22 pm
Posts: 3
I tried it, but the error persists... :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 1:02 pm 
Regular
Regular

Joined: Wed May 11, 2005 11:57 pm
Posts: 80
vivigrieco wrote:
I tried it, but the error persists... :(

Are you sure that the session that you're calling lock on is open and connected? ie., you haven't called theSession.close() or theSession.disconnect(), have you?


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

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.