Actually, I think the problem is the opposite. I AM calling session.merge(account) in my method.
I believe the issue is that since this is an ajax type application, two calls from the same client can come in 'near' simultaneously, but on different threads. Since it is different threads, when I call 'SessionFactory.getCurrentSession()', I do get two different sessions.
However, when the 2nd session.merge(account) is called (which happens before the first call ends), I get the error below.
example:
Code:
void getWidgets(Account account) {
System.out.println("getWidget Start - Thread is: " + Thread.currentThread());
beginTransaction();
session = getSession();
account = session.merge(account);
getWidgets(account);
commit();
System.out.println("getWidget End");
}
What I see in the console then is:
Code:
getWidget Start - Thread is: Thread[HttpSession-2,5]
getWidget Start - Thread is: Thread[HttpSession-5,5]
getWidgetEnd
Exception org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions.
The exception is thrown on the 'merge' line.