The Joys of Hibernate

I just spent the last few days troubleshooting a HibernateException with the error message Illegal attempt to associate a collection with two open sessions. After much Googling, I had tried every solution I could find, and none of them worked – so hopefully this solution will make it into the next person’s search.

In my case, the issue was that I was taking a persistent object, storing it in the HTTP session, and trying to reconstitute it later. By storing the ID in the browser session and loading by ID each time, the error was eliminated.

I hope this helps someone – if so, or if you’re having a similar issue, post in the comments!