Advertisement
Home > Hibernate Tutorial > SessionFactory > Question on Session Factory CreationPlease log in to add or reply to any matter<- requires login or
RMI Example

Home > Hibernate Tutorial > SessionFactory > Question on Session Factory Creation
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 :
Interview Questions
Description : On Hibernate
More...


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

Hibernate Tutorial,SessionFactory,Question-on-Session-Factory-Creation
Author : admin
Date (Year/Month/Date): 2009-01-25 Can any one suggest me on how to create Hibernate SessionFactory using Spring Framework?
 
 
 
Replied By ->
Sameer
I think, you can use Servlet that loads at web server start up or Filter that is invoked on every request, 
to create Hibernate SessionFactory by using hibernate.cfg.xml file
and using Configuration API from Hibernate.

But remember to create SessionFactory for once, for a database and
reuse it , as it is very expensive interms of resources to create Hibernate SessionFactory.

Thanks,
Sameer.
 

Commented By ->
Amit
There are two ways one can load application context descriptor
XML file for Spring Framework, that are by using context Listener
or by using context loader Servlet. Remember to provide context-param as the location of the
applicationContext file as
mentioned below:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/spring-config/applicationContext.xml</param-value>
</context-param>


Spring context Listener can be configured in web.xml file of
the web application as mentioned below:


<listener>
<listener-class>
  org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>


OR

Context loader servlet from Spring Framework to be mentione d in
web.xml web application descriptor file as :


<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
  org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


Hope this Helps.

Commented By ->
Amit
Another API org.springframework.context.support.ClassPathXmlApplicationContext
can be used with the application context XML file along with complete path.
In onw of the example I have used ClassPathXmlApplicationContext in SessionFactoryProvider
as follows:

  BeanFactory beanFactory = 
     new ClassPathXmlApplicationContext
                         ("/WEB-INF/config/spring-config/applicationContext.xml");
  this.sessFactory = (SessionFactory) beanFactory.getBean("mySessionFactory");
	


And it worked without any exception.
Please write your Comment on this Matter
(This will be visible if found suitable):
Name: *
Email (will not be displayed): *
Matter: *
29,25
Enter bigger number from above :*
Home > Hibernate Tutorial > SessionFactory > Question on Session Factory Creation
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 *:
8,3
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.