public class DependencyInjectionInterceptorFactoryBean extends DependencyInjectionAspectSupport implements org.springframework.beans.factory.FactoryBean
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.
Interceptor
Modifier and Type | Class and Description |
---|---|
protected class |
DependencyInjectionInterceptorFactoryBean.DependencyInjectionInterceptor
Class of Hibernate Interceptor returned by this factory.
|
DependencyInjectionAspectSupport.NoAutowiringConfigurationForClassException
Modifier and Type | Field and Description |
---|---|
static AtomicBoolean |
ENABLED |
autowireByTypeClasses, log
Constructor and Description |
---|
DependencyInjectionInterceptorFactoryBean() |
Modifier and Type | Method and 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
|
addAutowireByNameClass, addAutowireByTypeClass, addManagedClassToPrototypeMapping, afterPropertiesSet, autowireProperties, createAndConfigure, getAutowireByNameClasses, getAutowireByTypeClasses, getBeanFactory, getDefaultAutowireMode, getManagedClassToPrototypeNames, setAutowireByNameClasses, setAutowireByTypeClasses, setBeanFactory, setDefaultAutowireMode, setManagedClassNamesToPrototypeNames, validateConfiguration
public static final AtomicBoolean ENABLED
public DependencyInjectionInterceptorFactoryBean()
public void setNextInterceptor(org.hibernate.Interceptor nextInterceptor)
public org.hibernate.Interceptor getNextInterceptor()
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
sessionFactory
- bean name of the Hibernate SessionFactory
this interceptor should configure persistent object instances forpublic void setSessionFactoryName(String sessionFactoryName)
sessionFactoryName
- bean name of the Hibernate SessionFactory
this interceptor should configure persistent object instances forprotected void validateProperties()
DependencyInjectionAspectSupport
validateProperties
in class DependencyInjectionAspectSupport
public Object getObject() throws Exception
getObject
in interface org.springframework.beans.factory.FactoryBean
Exception
public Class getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean
Copyright © 2020 Atlassian Software Systems Pty Ltd. All rights reserved.