Forums Register Login

Is Hibernate Session object is thread-safe ?

+Pie Number of slices to send: Send
Is Hibernate Session object is thread-safe ?
If not, how to insure data integrity between multiple request?
+Pie Number of slices to send: Send
The Session object should only by used by a single Thread.
You usually (99% of the time) open/get a session with each user request and close is when its over.

This is from the javadocs(http://www.hibernate.org/hib_docs/v3/api/org/hibernate/Session.html):

<quote>
It is not intended that implementors be threadsafe. Instead each thread/transaction should obtain its own instance from a SessionFactory.
</quote>

Cheers!
+Pie Number of slices to send: Send
 

Originally posted by Xavier George:
Is Hibernate Session object is thread-safe ?
If not, how to insure data integrity between multiple request?



There are design patterns for Hibernate to handle these types of Conversations. On the hibernate.org website on their wiki pages describes how to do this. Also in the Java Persistence with Hibernate book, there is a good chapter on conversations.

Good Luck

Mark
+Pie Number of slices to send: Send
If you put this statement in your configuration file, the session will be bound to the thresd
<property name="hibernate.current_session_context_class">thread</property>

In your Java class you call getCurrentSession() from the SessionFactory to obtain a session object that is bound to this thread.
[ April 18, 2007: Message edited by: Hanna Habashy ]
Pay attention! Tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 25162 times.
Similar Threads
are request attributes and session attributes thread safe?
Can I use Hibernate in my RFID based attendance tracking application?
sharing the session object
Is there a default cache?
Is session object thread safe.
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 05:08:51.