Hibernate Interview Questions and Answers
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:
- What is Hibernate?
- What is ORM?
- What does an ORM solution comprises of?
- What are the different levels of ORM quality?
- What the Core interfaces are of hibernate framework?