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

@@ -232,8 +232,9 @@ public abstract class SessionFactoryBuilderSupport<This extends SessionFactoryBu
/**
* Build the underlying Hibernate SessionFactory.
* @return the raw SessionFactory (potentially to be wrapped with a
* transaction-aware proxy before it is exposed to the application)
* @return the {@code SessionFactory}, potentially wrapped as a
* {@code DisposableBean} and/or transaction-aware proxy before it is exposed to the
* application.
* @throws Exception in case of initialization failure
*/
public SessionFactory buildSessionFactory() throws Exception {
@@ -244,8 +245,9 @@ public abstract class SessionFactoryBuilderSupport<This extends SessionFactoryBu
/**
* Populate the underlying {@code Configuration} instance with the various
* properties of this builder. Customization may be performed through
* {@code pre*} and {@code post*} methods.
* properties of this builder, then return the raw session factory resulting from
* calling {@link Configuration#buildSessionFactory()}. Customization may be performed
* through {@code pre*} and {@code post*} methods.
* @see #preBuildSessionFactory()
* @see #postProcessMappings()
* @see #postBuildSessionFactory()
@@ -565,8 +567,9 @@ public abstract class SessionFactoryBuilderSupport<This extends SessionFactoryBu
* <p>Subclasses 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<This extends SessionFactoryBu
this.beanClassLoader,
new Class<?>[] {
SessionFactory.class,
SessionFactoryImplementor.class,
DisposableBean.class
},
new InvocationHandler() {