The following is my code.
The applicationContext.xmlCode:public final void testApproveDocApprovalWorkFlowItem() { ApplicationContext context = null; try { context = new ClassPathXmlApplicationContext("applicationContext.xml"); } catch(Exception e) { e.printStackTrace(); } DocApprovalWorkflowDAO docApprovalDao = (DocApprovalWorkflowDAO)context.getBean("DocApprovalWorkflowDao"); docApprovalDao.approveDocApprovalWorkFlowItem(id.intValue()); DocApprovalWorkflow obj = docApprovalDao.load(id); boolean result = obj.isApproved().booleanValue(); assertTrue(result); }
Code:<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"[ <!ENTITY DataSourceBean "org.apache.commons.dbcp.BasicDataSource"> <!ENTITY LocalSessionFactoryBean "org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <!ENTITY HibernateTransactionManager "org.springframework.orm.hibernate3.HibernateTransactionManager"> ... <!-- Hibernate SessionFactory --> <bean id="sessionFactory" class="&LocalSessionFactoryBean;"> <property name="mappingDirectoryLocations"> <list> <value>classpath:com/synesis7/i3/model/hibernate/</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.cglib.use_reflection_optimizer">false</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.default_schema">WES</prop> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> </props> </property> <property name="dataSource"> <ref bean="dataSource"/> </property> </bean> ... <bean id="abstractSessionFactoryHost" abstract="true"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="transactionManager" class="&HibernateTransactionManager;" parent="abstractSessionFactoryHost" /> <bean id="DocApprovalWorkflowDao" class="&DocApprovalWorkflowDAOHibernate;" parent="abstractSessionFactoryHost" />Why OH why, do I get a Lazy Initialization error on the line...Code:org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:56)
boolean result = obj.isApproved().booleanValue();
That just seems silly to me. At that point, I am using my POJO that represents that DB table. Spring and Hibernate have done their work for me. What is the correct way to handle this?
Thank you.


Reply With Quote
