org.springframework.orm.hibernate3
Class SessionFactoryBuilder

java.lang.Object
  extended by org.springframework.orm.hibernate3.SessionFactoryBuilderSupport<SessionFactoryBuilder>
      extended by org.springframework.orm.hibernate3.SessionFactoryBuilder
Direct Known Subclasses:
LocalSessionFactoryBean

public class SessionFactoryBuilder
extends SessionFactoryBuilderSupport<SessionFactoryBuilder>

Hibernate Configuration builder suitable for use within Spring @Configuration class @Bean methods. For complete details on features, see the JavaDoc for the SessionFactoryBuilderSupport superclass. For use in Spring XML configuration, see the LocalSessionFactoryBean subclass.

As noted in SessionFactoryBuilderSupport JavaDoc, this class requires Hibernate 3.2 or later; it additionally requires that the Java Persistence API and Hibernate Annotations add-ons are present.

Setter methods return the builder instance in order to facilitate a concise and convenient method-chaining style. For example:

 @Configuration
 public class DataConfig {
     @Bean
     public SessionFactory sessionFactory() {
         return new SessionFactoryBean()
             .setDataSource(dataSource())
             .setMappingLocations("classpath:com/myco/*.hbm.xml"})
             .buildSessionFactory();
     }
 }
 

Most Hibernate configuration operations can be performed directly against this API; however you may also access access and configure the underlying Configuration object by using the SessionFactoryBuilderSupport.doWithConfiguration(org.springframework.orm.hibernate3.HibernateConfigurationCallback) method and providing a HibernateConfigurationCallback as follows:

 SessionFactory sessionFactory =
     new SessionFactoryBuilder()
         // ...
         .doWithConfiguration(new HibernateConfigurationCallback<Configuration>() {
             public void configure(Configuration cfg) {
                 cfg.setNamingStrategy(MyNamingStrategy.class);
             }
          })
         .buildSessionFactory();
 

Since:
3.1
Author:
Juergen Hoeller, Chris Beams
See Also:
SessionFactoryBuilderSupport, LocalSessionFactoryBean, AnnotationSessionFactoryBuilder, AnnotationSessionFactoryBean

Field Summary
 
Fields inherited from class org.springframework.orm.hibernate3.SessionFactoryBuilderSupport
logger
 
Constructor Summary
SessionFactoryBuilder()
          Construct a new SessionFactoryBuilder
SessionFactoryBuilder(DataSource dataSource)
          Construct a new SessionFactoryBuilder with the given Spring-managed DataSource instance.
 
Method Summary
protected  Class<? extends org.hibernate.cfg.Configuration> getDefaultConfigurationClass()
          Return the default Configuration type used by this instance.
 
Methods inherited from class org.springframework.orm.hibernate3.SessionFactoryBuilderSupport
afterSessionFactoryCreation, beforeSessionFactoryDestruction, buildSessionFactory, createDatabaseSchema, doBuildSessionFactory, doWithConfiguration, dropDatabaseSchema, executeSchemaScript, executeSchemaStatement, getBeanClassLoader, getCacheRegionFactory, getConfigTimeDataSource, getConfigTimeLobHandler, getConfigTimeTransactionManager, getConfiguration, getDataSource, getHibernateProperties, getSessionFactory, isExposeTransactionAwareSessionFactory, isUseTransactionAwareDataSource, newConfiguration, newSessionFactory, postBuildSessionFactory, postProcessConfiguration, postProcessMappings, preBuildSessionFactory, setCacheableMappingLocations, setCacheRegionFactory, setClassLoader, setCollectionCacheStrategies, setConfigLocation, setConfigLocations, setConfigurationClass, setDataSource, setEntityCacheStrategies, setEntityInterceptor, setEventListeners, setExposeTransactionAwareSessionFactory, setFilterDefinitions, setHibernateProperties, setJtaTransactionManager, setLobHandler, setMappingDirectoryLocations, setMappingJarLocations, setMappingLocations, setMappingResources, setNamingStrategy, setSchemaUpdate, setTypeDefinitions, setUseTransactionAwareDataSource, updateDatabaseSchema, validateDatabaseSchema, wrapSessionFactoryIfNecessary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionFactoryBuilder

public SessionFactoryBuilder()
Construct a new SessionFactoryBuilder


SessionFactoryBuilder

public SessionFactoryBuilder(DataSource dataSource)
Construct a new SessionFactoryBuilder with the given Spring-managed DataSource instance.

See Also:
SessionFactoryBuilderSupport.setDataSource(javax.sql.DataSource)
Method Detail

getDefaultConfigurationClass

protected Class<? extends org.hibernate.cfg.Configuration> getDefaultConfigurationClass()
Return the default Configuration type used by this instance. May be overridden with SessionFactoryBuilderSupport.setConfigurationClass(Class).

This implementation returns org.hibernate.cfg.Configuration

Specified by:
getDefaultConfigurationClass in class SessionFactoryBuilderSupport<SessionFactoryBuilder>
See Also:
SessionFactoryBuilderSupport.setConfigurationClass(Class)