| |
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?
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. |
| |
|
|