Class DependencyInjectionInterceptorFactoryBean
- java.lang.Object
-
- org.springframework.orm.hibernate.support.DependencyInjectionAspectSupport
-
- org.springframework.orm.hibernate.support.DependencyInjectionInterceptorFactoryBean
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,org.springframework.beans.factory.FactoryBean
,org.springframework.beans.factory.InitializingBean
public class DependencyInjectionInterceptorFactoryBean extends DependencyInjectionAspectSupport implements org.springframework.beans.factory.FactoryBean
Allows Spring to create and wire up objects that come from Hibernate. This enables richer domain models, with domain objects able to access business objects.When creating such objects in application code, before persisting them, you can apply configuration manually via Setters, use factory autowiring, or obtain a prototype from the factory. A dependency on Spring IoC can be avoided by using a lookup-method to obtain the prototype instance.
This is a factory bean, as we want to extend DependencyInjectionAspectSupport yet be usable as a Hibernate Interceptor.
Typically, the Hibernate SessionFactory will be set via the "sessionFactoryName" property: this avoids a circular dependency between SessionFactory (requiring an Interceptor) and this Interceptor (requiring a SessionFactory).
Based on a constribution by Oliver Hutchison. Thanks also to Seth Ladd.
- Since:
- 1.2
- Author:
- Rod Johnson
- See Also:
Interceptor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
DependencyInjectionInterceptorFactoryBean.DependencyInjectionInterceptor
Class of Hibernate Interceptor returned by this factory.-
Nested classes/interfaces inherited from class org.springframework.orm.hibernate.support.DependencyInjectionAspectSupport
DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
-
-
Field Summary
Fields Modifier and Type Field Description static AtomicBoolean
ENABLED
-
Fields inherited from class org.springframework.orm.hibernate.support.DependencyInjectionAspectSupport
autowireByTypeClasses, log
-
-
Constructor Summary
Constructors Constructor Description DependencyInjectionInterceptorFactoryBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.hibernate.Interceptor
getNextInterceptor()
Reutn the next Interceptor in the chain, or null if this is the only interceptor.Object
getObject()
Class
getObjectType()
boolean
isSingleton()
void
setNextInterceptor(org.hibernate.Interceptor nextInterceptor)
As Hibernate doesn't support chaining of interceptors natively, we add the ability for chaining via a delegate.void
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
We need the Hibernate SessionFactory to work out identifier property name to set PK on object.void
setSessionFactoryName(String sessionFactoryName)
Alternative to the sessionFactory property.protected void
validateProperties()
Subclasses should implement this to validate their configuration-
Methods inherited from class org.springframework.orm.hibernate.support.DependencyInjectionAspectSupport
addAutowireByNameClass, addAutowireByTypeClass, addManagedClassToPrototypeMapping, afterPropertiesSet, autowireProperties, createAndConfigure, getAutowireByNameClasses, getAutowireByTypeClasses, getBeanFactory, getDefaultAutowireMode, getManagedClassToPrototypeNames, setAutowireByNameClasses, setAutowireByTypeClasses, setBeanFactory, setDefaultAutowireMode, setManagedClassNamesToPrototypeNames, validateConfiguration
-
-
-
-
Field Detail
-
ENABLED
public static final AtomicBoolean ENABLED
-
-
Method Detail
-
setNextInterceptor
public void setNextInterceptor(org.hibernate.Interceptor nextInterceptor)
As Hibernate doesn't support chaining of interceptors natively, we add the ability for chaining via a delegate.
-
getNextInterceptor
public org.hibernate.Interceptor getNextInterceptor()
Reutn the next Interceptor in the chain, or null if this is the only interceptor.
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
We need the Hibernate SessionFactory to work out identifier property name to set PK on object.- Parameters:
sessionFactory
- bean name of the Hibernate SessionFactory this interceptor should configure persistent object instances for
-
setSessionFactoryName
public void setSessionFactoryName(String sessionFactoryName)
Alternative to the sessionFactory property. Use this property to avoid circular dependencies between interceptor and SessionFactory. The session factory will be looked up on validation.- Parameters:
sessionFactoryName
- bean name of the Hibernate SessionFactory this interceptor should configure persistent object instances for
-
validateProperties
protected void validateProperties()
Description copied from class:DependencyInjectionAspectSupport
Subclasses should implement this to validate their configuration- Specified by:
validateProperties
in classDependencyInjectionAspectSupport
-
getObject
public Object getObject() throws Exception
- Specified by:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean
- Throws:
Exception
-
getObjectType
public Class getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean
-
isSingleton
public boolean isSingleton()
- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean
-
-