In my Hibernate 3.1 web application, I'm allowing the user to save to the database in one session while a background thread is reading data from the database in a different session. I'm using hibernate.current_session_context_class="thread" and GetCurrentSession() to manage my sessions, guaranteeing that each thread has its own session. In theory I thought that would work fine, but I'm encountering strange problems. The saving works, but right after it's done then the background thread tries to update the same objects that were just saved by the saving thread (as evidenced by duplicate HQL statements in the log), even though it never even touches those objects! I've also gotten some NonUniqueObjectException and StaleObjectExceptions that are probably related to that problem too. How can this be, and how can I fix it? It doesn't make any sense...
Any help would be much appreciated! I'm at my wit's end :(
|