From 5aa24af1269bf0ac9691afc63da6f6051543ad6a Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Thu, 7 Jul 2011 19:42:07 +0000 Subject: [PATCH] Implement SessionFactoryImplementor in SF proxies SessionFactoryBuilderSupport implementations create DisposableBean proxies for SessionFactory objects created using #buildSessionFactory. Prior to this change, these proxies create problems when working agaist SessionFactoryUtils.getDataSource(SessionFactory), because this method expects the given SessionFactory to implement Hibernate's SessionFactoryImplementor interface (which the stock SessionFactoryImpl does). With this change, the DisposableBean proxies created by SFBuilders now also implement SessionFactoryImplementor to satisfy this and probably other such cases. Issue: SPR-8469 --- ...ibernateSessionFactoryConfigurationTests.java | 4 +++- .../hibernate3/SessionFactoryBuilderSupport.java | 16 ++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/org.springframework.integration-tests/src/test/java/org/springframework/orm/hibernate3/HibernateSessionFactoryConfigurationTests.java b/org.springframework.integration-tests/src/test/java/org/springframework/orm/hibernate3/HibernateSessionFactoryConfigurationTests.java index 66344b54be..3f9df777ad 100644 --- a/org.springframework.integration-tests/src/test/java/org/springframework/orm/hibernate3/HibernateSessionFactoryConfigurationTests.java +++ b/org.springframework.integration-tests/src/test/java/org/springframework/orm/hibernate3/HibernateSessionFactoryConfigurationTests.java @@ -33,6 +33,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.AnnotationConfiguration; import org.hibernate.classic.Session; +import org.hibernate.engine.SessionFactoryImplementor; import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.BeanCreationException; @@ -131,10 +132,11 @@ public class HibernateSessionFactoryConfigurationTests { } @Test - public void builtSessionFactoryIsDisposableBeanProxy() { + public void builtSessionFactoryIsProxyImplementingDisposableBeanAndSessionFactoryImplementor() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AnnotationSessionFactoryConfig.class); SessionFactory sessionFactory = ctx.getBean(SessionFactory.class); assertThat(sessionFactory, instanceOf(DisposableBean.class)); + assertThat(sessionFactory, instanceOf(SessionFactoryImplementor.class)); assertThat(sessionFactory.toString(), startsWith("DisposableBean proxy for SessionFactory")); ctx.close(); assertTrue("SessionFactory was not closed as expected", sessionFactory.isClosed()); diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryBuilderSupport.java b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryBuilderSupport.java index a9a2295b12..8068ab91ac 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryBuilderSupport.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/SessionFactoryBuilderSupport.java @@ -232,8 +232,9 @@ public abstract class SessionFactoryBuilderSupportSubclasses may override this to implement transaction awareness through * a {@code SessionFactory} proxy for example, or even to avoid creation of the * {@code DisposableBean} proxy altogether. - * @param rawSf the raw {@code SessionFactory} as built by {@link #buildSessionFactory()} - * @return the {@code SessionFactory} reference to expose + * @param rawSf the raw {@code SessionFactory} as built by {@link #doBuildSessionFactory()} + * @return a proxied {@code SessionFactory} if wrapping was necessary, otherwise the + * original given 'raw' {@code SessionFactory} object. * @see #buildSessionFactory() */ protected SessionFactory wrapSessionFactoryIfNecessary(final SessionFactory rawSf) { @@ -574,6 +577,7 @@ public abstract class SessionFactoryBuilderSupport[] { SessionFactory.class, + SessionFactoryImplementor.class, DisposableBean.class }, new InvocationHandler() {