Announcement Announcement Module
Collapse
No announcement yet.
Spring HibernateDaoSupport keep the same Session open ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring HibernateDaoSupport keep the same Session open ?

    In the standalone application(single threaded command line tool) I am developing ,I use Spring +Hibernate. It has DAO and Service layers and for DAOs I use HibernateDAOSupport. The collections in domain model are lazy-loading.

    Since for lazy-loading I need to keep the Session opended,I open session at start of my application using:

    Code:
    HibernateTemplate tmpl;     
    SessionFactoryUtils.initDeferredClose(tmpl.getSessionFactory());
    
    //do file reads,parse CSV , persist objects (normally takes along time)
    //
    //Finally
    
    SessionFactoryUtils.processDeferredClose(tmpl.getSessionFactory());
    But during execution ,I get the error:

    Exception in thread "main" org.springframework.orm.hibernate3.HibernateSystem Exception: Illegal attempt to associate a collection with two open sessions; nested exception is org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
    Caused by: org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
    at org.hibernate.collection.AbstractPersistentCollect ion.setCurrentSession(AbstractPersistentCollection .java:410)
    at org.hibernate.event.def.OnUpdateVisitor.processCol lection(OnUpdateVisitor.java:43)
    at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:101)
    at org.hibernate.event.def.AbstractVisitor.processVal ue(AbstractVisitor.java:61)
    at org.hibernate.event.def.AbstractVisitor.processEnt ityPropertyValues(AbstractVisitor.java:55)
    at org.hibernate.event.def.AbstractVisitor.process(Ab stractVisitor.java:123)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.performUpdate(DefaultSaveOrUpdateEventListe ner.java:293)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.entityIsDetached(DefaultSaveOrUpdateEventLi stener.java:223)
    at org.hibernate.event.def.DefaultUpdateEventListener .performSaveOrUpdate(DefaultUpdateEventListener.ja va:33)
    at org.hibernate.event.def.DefaultSaveOrUpdateEventLi stener.onSaveOrUpdate(DefaultSaveOrUpdateEventList ener.java:70)
    at org.hibernate.impl.SessionImpl.fireUpdate(SessionI mpl.java:564)
    at org.hibernate.impl.SessionImpl.update(SessionImpl. java:552)
    at org.hibernate.impl.SessionImpl.update(SessionImpl. java:544)
    at org.springframework.orm.hibernate3.HibernateTempla te$14.doInHibernate(HibernateTemplate.java:657)
    at org.springframework.orm.hibernate3.HibernateTempla te.execute(HibernateTemplate.java:372)
    at org.springframework.orm.hibernate3.HibernateTempla te.update(HibernateTemplate.java:654)
    at org.springframework.orm.hibernate3.HibernateTempla te.update(HibernateTemplate.java:650)
    at com.bigg.nihonbare.common.dao.hibernate.CommonDAOI mpl.updateFamily(CommonDAOImpl.java:40)
    at com.bigg.nihonbare.common.service.impl.CommonServi ceImpl.updateFamily(CommonServiceImpl.java:55)
    at com.bigg.nihonbare.util.flow.DynaRowHibernateUpdat eHandler.handleRow(DynaRowHibernateUpdateHandler.j ava:72)
    at com.bigg.nihonbare.util.parser.DynacomParser.parse (DynacomParser.java:85)
    at com.bigg.nihonbare.util.flow.ProcessFlow.doDatabas eUpdate(ProcessFlow.java:53)
    at com.bigg.nihonbare.util.App.main(App.java:101)
    [INFO] Closing Compass [compass]
    [INFO] Closed Compass [compass]
    How to fix this please?
Working...
X