This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes getting session from hibernate session factory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "getting session from hibernate session factory" Watch "getting session from hibernate session factory" New topic

getting session from hibernate session factory

vikram sisodia

Joined: Jul 27, 2006
Posts: 7
Hi all,
i am using hibernate 3.1 and writing some code for getting object from database code is written below:

But "HibernateSessionFactory.getSession()" taking a lot of time to execute.
please suggest me ways to speedy my hibernate application.

public Testinfo getUser(Integer userId) throws VdnsException
Testinfo testinfo = null;
Session session = null;
Transaction tx = null;
session = HibernateSessionFactory.getSession();
tx = session.beginTransaction();
testinfo = (Testinfo) session.get(Testinfo.class, userId);
return testinfo;
Jonathan Huang
Ranch Hand

Joined: Jun 23, 2006
Posts: 35
The reason might be because everytime you call HibernateSessionFactory it is instantiating a new SessionFactory.... which is bad. But I haven't seen all your code so I could be wrong.

For examples of a DAO patterns used with Hibernate, you can check out the CaveatEmptor example, HibernateSync, and after you have an understanding of those, you might like to check out Spring's IOC container.

CaveatEmptor can be found at:
Just do a google for HibernateSync
I agree. Here's the link:
subject: getting session from hibernate session factory
Similar Threads
Problem with inserting new data into database using hibernate
org hibernate exception GenericJDBCException
Hibernate's update problem
Using Hiberntate: adding new data to derby db from JSP form
Session problem