com.interface21.orm.hibernate
Class LocalSessionFactoryBean

java.lang.Object
  |
  +--com.interface21.orm.hibernate.LocalSessionFactoryBean
All Implemented Interfaces:
FactoryBean, InitializingBean

public class LocalSessionFactoryBean
extends java.lang.Object
implements FactoryBean, InitializingBean

FactoryBean that creates local Hibernate SessionFactory instances. Behaves like a SessionFactory instance when used as bean reference, e.g. for HibernateTemplate's sessionFactory property. Note that switching to JndiObjectFactoryBean is just a matter of configuration!

The typical usage will be to register this as singleton factory (for a certain underlying data source) in an application context, and give bean references to application services that need it.

This SessionFactory handling strategy is most appropriate for applications that solely use Hibernate for data access, probably using HibernateTransactionManager for transaction demarcation.

Since:
05.05.2003
Author:
Juergen Hoeller
See Also:
HibernateTemplate, HibernateTransactionManager, JndiObjectFactoryBean

Constructor Summary
LocalSessionFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
          Initialize the SessionFactory for the given or the default location.
 java.lang.Object getObject()
          Return the singleton SessionFactory.
 PropertyValues getPropertyValues()
          Property values to pass to new bean instances created by this factory.
 boolean isSingleton()
          Is the bean managed by this factory a singleton or a prototype?
 void setLocation(java.lang.String location)
          Set the location of the Hibernate XML config file, as URL or classpath resource location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalSessionFactoryBean

public LocalSessionFactoryBean()
Method Detail

setLocation

public void setLocation(java.lang.String location)
Set the location of the Hibernate XML config file, as URL or classpath resource location. Hibernate 2.0's default is the "/hibernate.cfg.xml", in the case of web applications normally in WEB-INF/classes.

afterPropertiesSet

public void afterPropertiesSet()
                        throws DataAccessResourceFailureException
Initialize the SessionFactory for the given or the default location.
Specified by:
afterPropertiesSet in interface InitializingBean
Throws:
DataAccessResourceFailureException - in case of initialization errors

getObject

public java.lang.Object getObject()
Return the singleton SessionFactory.
Specified by:
getObject in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
an instance of the bean

isSingleton

public boolean isSingleton()
Description copied from interface: FactoryBean
Is the bean managed by this factory a singleton or a prototype? That is, will getBean() always return the same object?
The singleton status of a FactoryBean will generally be provided by the owning BeanFactory.
Specified by:
isSingleton in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
is this bean a singleton

getPropertyValues

public PropertyValues getPropertyValues()
Description copied from interface: FactoryBean
Property values to pass to new bean instances created by this factory. Mapped directly onto the bean instance using reflection. This occurs after any configuration of the instance performed by the factory itself, and is an optional step within the control of the owning BeanFactory.
Specified by:
getPropertyValues in interface FactoryBean
Following copied from interface: com.interface21.beans.factory.FactoryBean
Returns:
PropertyValues to pass to each new instance, or null (the default) if there are no properties to pass to the instance.


Rod Johnson and Spring contributors 2001-2003.