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 db3695a7c872..a24370743d6f 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.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 @@ private boolean matchesEntityTypeFilter(MetadataReader reader, MetadataReaderFac 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 @@ else if (method.getName().equals("hashCode")) { 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);