1
votes

I have written a batch application which spawns multiple threads to read assigned files and save records to database. The architecture uses Spring context and Hibernate.

Transaction is managed by Spring and I am using SessionFactory.getCurrentSession to get a session to perform a save operation for each thread.

Consider that I have a generic DAO that handles get, save, update operations and a facade to hide Hibernate implementation, how can I be assured that two threads when invoking SessionFactory.getCurrentSession() are getting their dedicated Session object to perform DB operations.

I found a post in StackOverflow where someone recommended not to use current_session_context_class=thread when using spring managed transaction. what is the default implementation used by Spring for current_session_context_class property?

Thanks in Advance!

1

1 Answers

1
votes

As of Spring 2.0 Spring integrates with hibernate throuhg its own implementation(s) of the CurrentSessionContext interface provided by hibernate.

By default spring sets this to the SpringSessionContext to integrate properly. In general you don't want or need to mess with the current_session_context_class unless you are using JTA (although when using Hibernate 4 with a recent Spring version it should also just work).