From 01f115869b7af0e60e30c284d4238a2becca3548 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 20 Jun 2016 13:42:42 +0200 Subject: [PATCH] Bootstrap SessionFactory implements InfrastructureProxy interface for resource key unwrapping Issue: SPR-14379 --- .../orm/hibernate5/LocalSessionFactoryBuilder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java index db3695a7c87..a24370743d6 100644 --- a/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java +++ b/spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBuilder.java @@ -46,6 +46,7 @@ import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.springframework.core.InfrastructureProxy; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @@ -317,7 +318,7 @@ public class LocalSessionFactoryBuilder extends Configuration { public SessionFactory buildSessionFactory(AsyncTaskExecutor bootstrapExecutor) { Assert.notNull(bootstrapExecutor, "AsyncTaskExecutor must not be null"); return (SessionFactory) Proxy.newProxyInstance(this.resourcePatternResolver.getClassLoader(), - new Class[] {SessionFactoryImplementor.class}, + new Class[] {SessionFactoryImplementor.class, InfrastructureProxy.class}, new BootstrapSessionFactoryInvocationHandler(bootstrapExecutor)); } @@ -354,6 +355,10 @@ public class LocalSessionFactoryBuilder extends Configuration { else if (method.getName().equals("getProperties")) { return getProperties(); } + else if (method.getName().equals("getWrappedObject")) { + // Call coming in through InfrastructureProxy interface... + return getSessionFactory(); + } // Regular delegation to the target SessionFactory, // enforcing its full initialization... return method.invoke(getSessionFactory(), args);