|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.orm.hibernate3.AbstractSessionFactoryBean
org.springframework.orm.hibernate3.LocalSessionFactoryBean
org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
public class AnnotationSessionFactoryBean
Subclass of Spring's standard LocalSessionFactoryBean for Hibernate, supporting JDK 1.5+ annotation metadata for mappings.
Note: This class requires Hibernate 3.2 or later, with the Java Persistence API and the Hibernate Annotations add-on present.
Example for an AnnotationSessionFactoryBean bean definition:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="annotatedClasses"> <list> <value>test.package.Foo</value> <value>test.package.Bar</value> </list> </property> </bean>Or when using classpath scanning for autodetection of entity classes:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="packagesToScan" value="test.package"/> </bean>
AbstractSessionFactoryBean.setDataSource(javax.sql.DataSource)
,
LocalSessionFactoryBean.setHibernateProperties(java.util.Properties)
,
setAnnotatedClasses(java.lang.Class[])
,
setAnnotatedPackages(java.lang.String[])
Field Summary |
---|
Fields inherited from class org.springframework.orm.hibernate3.AbstractSessionFactoryBean |
---|
logger |
Constructor Summary | |
---|---|
AnnotationSessionFactoryBean()
|
Method Summary | |
---|---|
protected void |
postProcessAnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration config)
To be implemented by subclasses which want to to perform custom post-processing of the AnnotationConfiguration object after this FactoryBean performed its default initialization. |
protected void |
postProcessConfiguration(org.hibernate.cfg.Configuration config)
This default implementation delegates to postProcessAnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration) . |
protected void |
postProcessMappings(org.hibernate.cfg.Configuration config)
Reads metadata from annotated classes and packages into the AnnotationConfiguration instance. |
protected void |
scanPackages(org.hibernate.cfg.AnnotationConfiguration config)
Perform Spring-based scanning for entity classes. |
void |
setAnnotatedClasses(Class[] annotatedClasses)
Specify annotated classes, for which mappings will be read from class-level JDK 1.5+ annotation metadata. |
void |
setAnnotatedPackages(String[] annotatedPackages)
Specify the names of annotated packages, for which package-level JDK 1.5+ annotation metadata will be read. |
void |
setConfigurationClass(Class configurationClass)
Specify the Hibernate Configuration class to use. |
void |
setEntityTypeFilters(TypeFilter[] entityTypeFilters)
Specify custom type filters for Spring-based scanning for entity classes. |
void |
setPackagesToScan(String[] packagesToScan)
Set whether to use Spring-based scanning for entity classes in the classpath instead of listing annotated classes explicitly. |
void |
setResourceLoader(ResourceLoader resourceLoader)
Set the ResourceLoader that this object runs in. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AnnotationSessionFactoryBean()
Method Detail |
---|
public void setConfigurationClass(Class configurationClass)
LocalSessionFactoryBean
Can be set to "org.hibernate.cfg.AnnotationConfiguration" for using Hibernate3 annotation support (initially only available as alpha download separate from the main Hibernate3 distribution).
Annotated packages and annotated classes can be specified via the corresponding tags in "hibernate.cfg.xml" then, so this will usually be combined with a "configLocation" property that points at such a standard Hibernate configuration file.
setConfigurationClass
in class LocalSessionFactoryBean
LocalSessionFactoryBean.setConfigLocation(org.springframework.core.io.Resource)
,
Configuration
,
AnnotationConfiguration
public void setAnnotatedClasses(Class[] annotatedClasses)
AnnotationConfiguration.addAnnotatedClass(Class)
public void setAnnotatedPackages(String[] annotatedPackages)
AnnotationConfiguration.addPackage(String)
public void setPackagesToScan(String[] packagesToScan)
Default is none. Specify packages to search for autodetection of your entity
classes in the classpath. This is analogous to Spring's component-scan feature
(ClassPathBeanDefinitionScanner
).
public void setEntityTypeFilters(TypeFilter[] entityTypeFilters)
Default is to search all specified packages for classes annotated with
@javax.persistence.Entity
, @javax.persistence.Embeddable
or @javax.persistence.MappedSuperclass
, as well as for
Hibernate's special @org.hibernate.annotations.Entity
.
setPackagesToScan(java.lang.String[])
public void setResourceLoader(ResourceLoader resourceLoader)
ResourceLoaderAware
This might be a ResourcePatternResolver, which can be checked
through instanceof ResourcePatternResolver
. See also the
ResourcePatternUtils.getResourcePatternResolver
method.
Invoked after population of normal bean properties but before an init callback
like InitializingBean's afterPropertiesSet
or a custom init-method.
Invoked before ApplicationContextAware's setApplicationContext
.
setResourceLoader
in interface ResourceLoaderAware
resourceLoader
- ResourceLoader object to be used by this objectResourcePatternResolver
,
ResourcePatternUtils.getResourcePatternResolver(org.springframework.core.io.ResourceLoader)
protected void postProcessMappings(org.hibernate.cfg.Configuration config) throws org.hibernate.HibernateException
postProcessMappings
in class LocalSessionFactoryBean
config
- the current Configuration object
org.hibernate.HibernateException
- in case of Hibernate initialization errorsConfiguration.buildMappings()
protected void scanPackages(org.hibernate.cfg.AnnotationConfiguration config)
setPackagesToScan(java.lang.String[])
protected void postProcessConfiguration(org.hibernate.cfg.Configuration config) throws org.hibernate.HibernateException
postProcessAnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration)
.
postProcessConfiguration
in class LocalSessionFactoryBean
config
- the current Configuration object
org.hibernate.HibernateException
- in case of Hibernate initialization errorsConfiguration.buildMappings()
protected void postProcessAnnotationConfiguration(org.hibernate.cfg.AnnotationConfiguration config) throws org.hibernate.HibernateException
Note: As of Hibernate 3.6, AnnotationConfiguration's features
have been rolled into Configuration itself. Simply overriding
postProcessConfiguration(org.hibernate.cfg.Configuration)
becomes an option as well then.
config
- the current AnnotationConfiguration object
org.hibernate.HibernateException
- in case of Hibernate initialization errors
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |