max wrote:
thats a very wrong way of doing it ;)
please submit this as an issue to the jira (with testcase to show it), should be trivial to fix.
Well, would you care to explain. Basically, here's an example for you
hibPersistentClass p1 = session1.load(hibPersistentclass.class, 1);
// p1 has lazy collections and is a proxy
session1.evict(p1);
session2.saveOrUpdate(p1);
// error !!!! illegal attempt to associate a proxy with two sessions,
Well, if you look at the objects more closely, the proxies have indeed been removed from session1, p1 is detached and the only thing that remains is the reference to the old session (which is still open)
Now, when you try to change sessions by reassociating, then Hibernate doesn't let you because the old session is still open.
Passing setSession(null) to it, in this case allows you to remove the old session and the new one will get assigned as soon as you attach it to a new session.
What's wrong with that?