| |
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 :
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...
|
Written By : Amit
Title :
Interceptor use log SQL statements
Description :
example code More...
|
Written By : Amit
Title :
Class Hierarchy Persist example
Description :
code More...
|
| Tags/Keywords : 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 | |
Please be informed that NONE of the design/code from this
page is claiming to be some sort of best practices and we DO NOT expect
any of our visitor/reader of this page to assume this as some sort of
best practice for any context and should not be using this
as it is without appropriate evaluation to their, so to say,
specific programming context.
This page intends only to provide bit and piece of known ways for
doing some sort of example and may not be fit for any other purpose.
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?
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.
|
|
|
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. |
| | |
Commented By -> Amit | If Hibernate SessionFactory is being created by using Spring
Framework, and with required configuration settings, then one may have to use appropriate factory bean from
Spring Framework, with
datasource/jdbc driver specific configuration and with some of those configuration setting as
required(Please refer Spring Framework's documentations for details).
Even there are some of those example/sample implementation explained in some of those pages from this
website, as well.
|
| | Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> Hibernate Tutorial >>> ways create Hibernate SessionFactory >>> Example |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, 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.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|