Hibernate version: 3.2.5
Name and version of the database: SQL Server
Hi,
I have posted the same question at Spring forum as well. I am not sure if it is a Hibernate Problem.
I have a Standalone application where I am using Spring with Hibernate. I have an entity that contains another entity as a set.
Code:
<class name="Demo" table="DEMO">
...
...
<set name="addresses" inverse="true" cascade="save-update, delete, delete-orphan">
<key>
<column name="filing_id"/>
</key>
<one-to-many class="Address"/>
</set
I retrieve an object of type 'demo' at one place. And after some processing I retrieve addresses from the 'demo' object. At that point I get a LazyInitialization exception.
Code:
// Retrieving demoDAO and demoobject
DemoDAO dao = DAOFactory.instance().getDemoDAO();
Demo demo = dao.findById("100");
...
...
...
if (demo.getAddresses() != null && !demo.getAddresses().isEmpty()) {
demo.getAddresses().clear();
}
I get the following exception -
Quote:
(hibernate.LazyInitializationException 19 ) failed to lazily initialize a collection of role: com.novus.sec.filings.model.Filing.addresses, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.novus.sec.filings.model.Filing.addresses, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:358)
at org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:350)
at org.hibernate.collection.AbstractPersistentCollect ion.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentSet.isEmpty(Per sistentSet.java:146)
I am using Spring Transaction. Please find below my ApplicationContext.file -
Quote:
<bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="demoTarget" class="com.xxx.sec.filings.dao.hibernate.DemoDAOHi bernate">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<bean id="demoDAO" class="org.springframework.aop.framework.ProxyFact oryBean">
<property name="proxyInterfaces">
<value>com.xxx.sec.filings.dao.demoDAO</value>
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
<value>demoDAOTarget</value>
</list>
</property>
</bean>
I am kind of new to using Spring Hibernate Template. Can anyone please help me?
Thanks,
Manu