Auto-unwrap SessionFactoryBuilder-created proxies
SessionFactory proxies created by (Annotation)SessionFactoryBuilder now implement InfrastructureProxy to ensure they are automatically unwrapped for transaction resource management purposes. Issue: SPR-8492
This commit is contained in:
@@ -52,6 +52,7 @@ import org.hibernate.transaction.JTATransactionFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.core.InfrastructureProxy;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -566,6 +567,7 @@ public abstract class SessionFactoryBuilderSupport<This extends SessionFactoryBu
|
||||
new Class<?>[] {
|
||||
SessionFactory.class,
|
||||
SessionFactoryImplementor.class,
|
||||
InfrastructureProxy.class,
|
||||
DisposableBean.class
|
||||
},
|
||||
new InvocationHandler() {
|
||||
@@ -573,6 +575,9 @@ public abstract class SessionFactoryBuilderSupport<This extends SessionFactoryBu
|
||||
if (ReflectionUtils.isToStringMethod(method)) {
|
||||
return String.format("DisposableBean proxy for SessionFactory [%s]", rawSf.toString());
|
||||
}
|
||||
if (method.equals(InfrastructureProxy.class.getMethod("getWrappedObject"))) {
|
||||
return rawSf;
|
||||
}
|
||||
if (method.equals(DisposableBean.class.getMethod("destroy"))) {
|
||||
closeHibernateSessionFactory(SessionFactoryBuilderSupport.this, rawSf);
|
||||
rawSf.close();
|
||||
|
||||
Reference in New Issue
Block a user