OK, the DAOs, etc. all call my HibernateSessionFactory.currentSession()
currentSession() looks like this:
Code:
public static Session currentSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || session.isOpen() == false) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}
return session;
}
Before any DAOs make an attempt to call "currentSession", I pull the Hibernate Session from the HTTP Session and force the threadLocal referenced above to be the "existing HibSession fetched from the HttpSession"
Thus, the currentSession() reads: "if the threadlocal wasn't already set, retrieve a new hibSession object"
Typically, that only happens at login, when the user doesn't have a Hibernate Session yet.
My problem is that it frequently winds up assigning the same Hibernate Session to TWO (or a dozen) User/HttpSessions.
Then I wind up with "two collections with same identifier already in Session" and "object was already evicted" or "already flushed" problems from two people playing in the same sandbox.
I'll double check and put the session.hashCode out to the log file anytime "openSession" is called and see if it IS returning a different one each time and somewhere I'm fouling it up.