Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Hibernate%20Interview%20Questions%20and%20Answers

Question: What is a Session? Can you share a session object between different threads?
Answer: Session is a light weight and a non-threadsafe object (No, you cannot share it between threads) that represents a single unit-of-work with the database. Sessions are opened by a SessionFactory and then are closed when all work is complete. Session is the primary interface for the persistence service. A session obtains a database connection lazily (i.e. only when required). To avoid creating too many sessions ThreadLocal class can be used as shown below to get the current session no matter how many times you make call to the currentSession() method.
Is it helpful? Yes No

Most helpful rated by users:

©2024 WithoutBook