From 08ccd19c76a71be3edf98f1a7f62cdd73ae98c9b 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 git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4683 50f2f4bb-b051-0410-bef5-90022cba6387 --- ...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 66344b54bee..3f9df777adf 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 a9a2295b123..8068ab91aca 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() {