Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 575997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:00:00+00:00 2026-05-13T14:00:00+00:00

In the standalone application(single threaded command line tool) I am developing ,I use Spring

  • 0

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:

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.HibernateSystemException:
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.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:410)
at
org.hibernate.event.def.OnUpdateVisitor.processCollection(OnUpdateVisitor.java:43)
at
org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:101)
at
org.hibernate.event.def.AbstractVisitor.processValue(AbstractVisitor.java:61)
at
org.hibernate.event.def.AbstractVisitor.processEntityPropertyValues(AbstractVisitor.java:55)
at
org.hibernate.event.def.AbstractVisitor.process(AbstractVisitor.java:123)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:223)
at
org.hibernate.event.def.DefaultUpdateEventListener.performSaveOrUpdate(DefaultUpdateEventListener.java:33)
at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at
org.hibernate.impl.SessionImpl.fireUpdate(SessionImpl.java:564)
at
org.hibernate.impl.SessionImpl.update(SessionImpl.java:552)

How to fix this?

at
org.hibernate.impl.SessionImpl.update(SessionImpl.java:544)
at
org.springframework.orm.hibernate3.HibernateTemplate$14.doInHibernate(HibernateTemplate.java:657)
at
org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:372)
at
org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:654)
at
org.springframework.orm.hibernate3.HibernateTemplate.update(HibernateTemplate.java:650)
at
com.bigg.nihonbare.common.dao.hibernate.CommonDAOImpl.updateFamily(CommonDAOImpl.java:40)
at
com.bigg.nihonbare.common.service.impl.CommonServiceImpl.updateFamily(CommonServiceImpl.java:55)
at
com.bigg.nihonbare.util.flow.DynaRowHibernateUpdateHandler.handleRow(DynaRowHibernateUpdateHandler.java:72)

NOTE : In my DAOs I only have used methods like;

return (Long) this.getHibernateTemplate().save(family);

return (Family) this.getHibernateTemplate().execute(
                new HibernateCallback() {
                    public Object doInHibernate(Session session) {
                        Criteria criteria = session
                                .createCriteria(Family.class);
                        criteria.add(Expression.eq("familyId", familyId));
                        if (criteria.list().size() > 0) {
                            return criteria.list().get(0);
                        }
                        return null;
                    }
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:00:00+00:00Added an answer on May 13, 2026 at 2:00 pm

    Watch for getHibernateTemplate().getSessionFactory().openSession() in your DAO, you might be ending up opening 2 sessions, since you lately switched to this architecture, I know it from your other previous question.

    Hint: Use getSession() instead. This SpringSource Forum’s thread might be helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.