Jegan Kunniya
Jegan Kunniya

Reputation: 992

Hibernate: When to use getSession() and when to use getCurrentSession()?

I have been using hibernate with Springs where i don't get to use getSession() or getCurrentSession() as the Spring container manages it.

But i came across this getSession() and getCurrentSession() methods while reading hibernate.

Can anyone explain when to use either of the methods?

Upvotes: 2

Views: 6581

Answers (1)

kgiannakakis
kgiannakakis

Reputation: 104168

getCurrentSession is a method of the SessionFactory interface. As the name implies, an implementation of this method is responsible for creating and managing sessions. What does "current" mean, depends on the implementation.

A getSession method is usually used by classes that build wrappers around Hibernate (like Spring's HibernateDaoSupport).

I don't think that there is a class that implements both of these methods. You can't compare them outside of the context they are used and the classes that implement them.

Upvotes: 2

Related Questions