Posted on 2011-03-24
Last Modified: 2012-05-11

I wou.d like to know what is HibernateUtil.getSessionFactory().close() method in hibernate. Where and how and why to use it. How is it different from session.close used in CRUD operations. Any ideas, resources, links, sample code highly appreciated. thanks in advance.
Question by:gudii9
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 47

Accepted Solution

for_yan earned 400 total points
ID: 35212013

HibernateUtil.getSessionFactory().close()  closes session factory, whereas session.close() closes particular session
I think there is big difference.

This is the explanation of the difference between Sessionfactory and the Session in Hibertnate Tuorial:

1.5.1 SessionFactory (org.hibernate.SessionFactory)

SessionFactory is a thread safe (immutable) cache of compiled mappings for a single database. Usually an application has a single SessionFactory. Threads servicing client requests obtain Sessions from the factory. The behavior of a SessionFactory is controlled by properties supplied at configuration time.

1.5.2 Session (org.hibernate.Session)

A session is a connected object representing a conversation between the application and the database. It wraps a JDBC connection and can be used to maintain the transactions. It also holds a cache of persistent objects,used when navigating the objects or looking up objects by identifier.
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 100 total points
ID: 35213247
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35213352
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.


Author Comment

ID: 35353907
which one is HibernateUtil  class here. Does it not provided by hibernate framework by default. I am not clear. please advise

Author Comment

ID: 35463003
any good video tutorials, online trainings on these intricate concepts. please advise
LVL 47

Expert Comment

ID: 35463097

This seesm to be the most viewed Youtube tutorial on Hibernate:

And great majority liked it.
This is the first part - then follow the links on YouTube

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question