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
This commit is contained in:
Chris Beams
2011-07-07 19:42:07 +00:00
parent c3f9e845e0
commit 5aa24af126
2 changed files with 13 additions and 7 deletions

View File

@@ -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());