HHH-13850 Clear the BytecodeProvider caches both after SessionFactory creation and stop

This commit is contained in:
Sanne Grinovero 2020-02-05 09:55:14 +00:00
parent 5c81089d65
commit 52ca2703f3
4 changed files with 42 additions and 3 deletions

View File

@ -20,10 +20,13 @@ import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.boot.SessionFactoryBuilder;
import org.hibernate.boot.TempTableDdlTransactionHandling;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.spi.BootstrapContext;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.bytecode.internal.SessionFactoryObserverForBytecodeEnhancer;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.cache.spi.TimestampsCacheFactory;
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.dialect.function.SQLFunction;
@ -459,6 +462,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
@Override
public SessionFactory build() {
metadata.validate();
final StandardServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
BytecodeProvider bytecodeProvider = serviceRegistry.getService( BytecodeProvider.class );
addSessionFactoryObservers( new SessionFactoryObserverForBytecodeEnhancer( bytecodeProvider ) );
return new SessionFactoryImpl( metadata, buildSessionFactoryOptions() );
}

View File

@ -0,0 +1,35 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.bytecode.internal;
import org.hibernate.SessionFactory;
import org.hibernate.SessionFactoryObserver;
import org.hibernate.bytecode.spi.BytecodeProvider;
public final class SessionFactoryObserverForBytecodeEnhancer implements SessionFactoryObserver {
private final BytecodeProvider bytecodeProvider;
public SessionFactoryObserverForBytecodeEnhancer(BytecodeProvider bytecodeProvider) {
this.bytecodeProvider = bytecodeProvider;
}
@Override
public void sessionFactoryCreated(final SessionFactory factory) {
this.bytecodeProvider.resetCaches();
}
@Override
public void sessionFactoryClosing(final SessionFactory factory) {
this.bytecodeProvider.resetCaches();
}
@Override
public void sessionFactoryClosed(final SessionFactory factory) {
this.bytecodeProvider.resetCaches();
}
}

View File

@ -159,7 +159,7 @@ public final class ByteBuddyState {
/**
* Wipes out all known caches used by ByteBuddy. This implies it might trigger the need
* to re-create some helpers if used at runtime, especially as this state is shared by
* to re-create some helpers if used at runtime, especially as this state might be shared by
* multiple SessionFactory instances, but at least ensures we cleanup anything which is no
* longer needed after a SessionFactory close.
* The assumption is that closing SessionFactories is a rare event; in this perspective the cost

View File

@ -753,8 +753,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
* @throws HibernateException
*/
public void close() throws HibernateException {
//This is an idempotent operation so we can do it even before the checks (it won't hurt):
Environment.getBytecodeProvider().resetCaches();
synchronized (this) {
if ( isClosed ) {
if ( getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) {