This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate Helper Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Helper Class" Watch "Hibernate Helper Class" New topic

Hibernate Helper Class

Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
I am having trouble figuring out what this class is actually doing. I am using it and it is working fine, just not sure what is working fine...

Anyone have an explanation for me?

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Basically, what you have is a Singleton. See creating a SessionFactory is a big deal, it has so much work to do. It is considered a heavyweight object. So you want to make sure that you only create this once, hence the Singleton.

So anytime you app needs to get a Session, it can call the helper class Singleton get the instance of SessionFactory and call openSession() on it. Session objects are very lightweight. Almost empty when you call that method, there is a JDBC Connection set in the new Session, but it will get the Connection from the COnnection pool.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
Great thanks, I didn't realize that the session factory was going to be such a heavyweight object.

I agree. Here's the link:
subject: Hibernate Helper Class
It's not a secret anymore!