Advertisement
Home > Hibernate Tutorial > ways create Hibernate SessionFactory > ExamplePlease log in to add or reply to any matter<- requires login or
RMI Example

Home > Hibernate Tutorial > ways create Hibernate SessionFactory > Example
Struts Tutorials:
Struts2 Tag CheckBoxList
, Checkbox, Iterator, IF
Struts2 Tag Library Example Struts2 Tiles Example Struts2 Tiles I18N Example Struts2 Questions Struts Tiles I18N Example Struts Eclipse MVC Struts2 Tags Struts2 Example and Tutorial Struts MVC Struts2 Validation
Hibernate Tutorials: Hibernate Case Study Class Hierarchy Persist Example Using Hibernate Interceptor Hibernate Questions with Answer Hibernate Many-to-Many Mapping Example Hibernate one-to-many Mapping Example Hibernate and ORM tools Spring Hibernate Example Hibernate SessionFactory Example Hibernate Mapping Class Hierarchy Hibernate Questions Hibernate SessionFactory Questions Spring Hibernate Example: Spring Hibernate Case Study

Written By : Amit
Title :
mapping class hierarchy table per subclass
Description : Example
More...


Written By : Amit
Title :
ways create Hibernate SessionFactory
Description : Example
More...


Written By : Amit
Title :
Spring Hibernate Integration example
Description : Example
More...


Written By : Amit
Title :
ORM Hibernate Best FIT
Description : Discussion
More...


Written By : Amit
Title :
One to Many mapping example
Description : Code
More...


Written By : Amit
Title :
Many to Many Mapping Example
Description : code
More...


Written By : Amit
Title :
Interview questions answer
Description : discussion
More...

Hibernate SessionFactory, SessionFactory, Hibernate, Example, Code, Tutorial, Article
Author : Amit
Date (Year/Month/Date): 2009-02-18 How to create Hibernate SessionFactory a example discussed
 Hibernate SessionFactory -
 the factory that provides
 Session for working with
 database within a single
 transaction. Session can
 be taken from SessionFactory
 and after use can be flushed
 and closed. but SessionFactory
 should be created only for
 once, and it can be configured
 to accept DataSource,
 Transaction attributes.

How to create Hibernate SessionFactory? What strategy best
suits to initialize SessionFactory?

Advertisement
One way is to create SessionFactory from within a Utility class file that can be Singleton so that a single instace of SessionFactory an made available for a ClassLoader in JVM. But this way SessionFactory will be created on first client call and this may result in a delay in first client call being served. Or it could happen that due to some sort of database failure, SessionFactory may not be initialized properly and all client requests starts throwing exceptions. Or one can have Java Servlet to be loaded on startup, as can be defined in deployment descriptor web.xml file. This Servlet, in service method builds SessionFactory and puts it in a Singleton Utility class file for use. If in case this SessionFactory cannot be build, then this Servlet may send required notificaton to concern Administrator for action. Or one can have this Hibernate SessionFactory created inside a static initializer block of code inside some sort of Utility Java class that can be used in program code to retrieve SessionFactory. While creation of SessionFactory, one can opt for binding this Hibernate SessionFactory to be bound to JNDI, if the application is running in application server with initial context. Once bound to JNDI, this SessionFactory can be looked up by Service Locator and be served. This approach is suitable if there is any need for creating SessionFactory at one instance of application server and be reused across all the instances of application server nodes/instances in a cluster of application server. Hibernate SessionFactory can be created as a JMX service, by using JMX capabilities provided by application server. This way it is all the more interesting to manage SessionFactory remotely, like for example if SessionFactory will have to be re-created, then this JMX service can be re-started, without really re-starting the application.
Advertisement

Commented By ->
nagarajan M
Hibernate session factory instance clearly explained.Thanks

Commented By ->
Guddu
Hi Amit,

Read your thought on Hibernate SessionFactory.
So Hibernate SessionFactory can be created once per node
or server instance, or it could be created once and bound to 
JNDI of any perticular node.
Which approach is better, in your opinion??

If bound to one server noce and served by JNDI lookup,
then there could possibility of single point of failure, 
in case the same node goes down.

If Hibernate SessionFactory is created on all the instances
or server nodes in a cluster, I think, then it could have better 
performance and more availability, in terms of Database
connectivity/ interaction... What is your opinion??

Anybody else has any opinion to share here???
I Appreciate any answer to this question.
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
10,11
Enter bigger number from above :*
Home > Hibernate Tutorial > ways create Hibernate SessionFactory > Example
Visitor/User submitted related resources:
(Visible upon review and approved by this site Administrator)
Referred By Name *:
Resource URL *: (e.g, URL should be starting with http://www.-----.---)
 
Resource Short Description *:
13,15
Enter bigger number from above : *

Please log in to add or reply to any matter<- requires login
Log in or Register
This List is generated as on 2009-07-12 (YYYY-MM-DD)
#Discuss-these : questions-and-answer : Interview-Questions-on-Java
#Question-on-Session-Factory-Creation : SessionFactory : Hibernate-Tutorial
#On-Hibernate : Interview-Questions : Hibernate-Tutorial
#Example : mapping-class-hierarchy-table-per-subclass : Hibernate-Tutorial
#Example : ways-create-Hibernate-SessionFactory : Hibernate-Tutorial
#Example : Spring-Hibernate-Integration-example : Hibernate-Tutorial
#Discussion : ORM-Hibernate-Best-FIT : Hibernate-Tutorial
#Code : One-to-Many-mapping-example : Hibernate-Tutorial
#code : Many-to-Many-Mapping-Example : Hibernate-Tutorial
#discussion : Interview-questions-answer : Hibernate-Tutorial
#example-code : Interceptor-use-log-SQL-statements : Hibernate-Tutorial
#code : Class-Hierarchy-Persist-example : Hibernate-Tutorial
#discussion : Case-study-Hibernate : Hibernate-Tutorial
#With-Answer : Hibernate-Interview-Questions : Hibernate-Tutorial
#Discussed : Hibernate-Interview-questions-answer : Hibernate-Tutorial
#Question : Hibernate-Transaction : Hibernate-Tutorial
#Example-Case-study : Contextual-Session : Hibernate-Tutorial
#Design-with-example-code : Struts2-Hibernate : Hibernate-Tutorial
#Hibernate-query : Hibernate-Criteria : Hibernate-Tutorial
#Hibernate-Criteria-Example : Hibernate-Filter-Example : Hibernate-Tutorial
#Hibernate-Filter-Example : Hibernate-Filter : Hibernate-Tutorial
#Hibernate-Sample : Hibernate-many-to-one : Hibernate-Tutorial
#Hibernate-Sample-Example : Hibernate-named-query : Hibernate-Tutorial
#Composite-Primary-Key : Hibernate-Composite-Key : Hibernate-Tutorial
#Mapping-Example : Hibernate-one-to-one : Hibernate-Tutorial
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved.
CONTACT    PRIVACY POLICY    DISCLAIMER

This web site provides some of the information about various technologies, example 
code, tips, tutorials etc. Like any printed matterials, content of these pages may 
become out of date over a period of time. Therefore all visitor/users of this web 
site are requested/advised to refer to the originating parties/sources for the 
latest changes and happenings for detailed information. This information is not 
intended to be a substitute for the original reference provided by the originating 
parties/sources.