HHH-13850 Clear the BytecodeProvider caches both after SessionFactory creation and stop
This commit is contained in:
parent
5c81089d65
commit
52ca2703f3
|
@ -20,10 +20,13 @@ import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.SessionFactoryObserver;
|
import org.hibernate.SessionFactoryObserver;
|
||||||
import org.hibernate.boot.SessionFactoryBuilder;
|
import org.hibernate.boot.SessionFactoryBuilder;
|
||||||
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
import org.hibernate.boot.TempTableDdlTransactionHandling;
|
||||||
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
import org.hibernate.boot.spi.BootstrapContext;
|
import org.hibernate.boot.spi.BootstrapContext;
|
||||||
import org.hibernate.boot.spi.MetadataImplementor;
|
import org.hibernate.boot.spi.MetadataImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;
|
import org.hibernate.boot.spi.SessionFactoryBuilderImplementor;
|
||||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
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.cache.spi.TimestampsCacheFactory;
|
||||||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||||
import org.hibernate.dialect.function.SQLFunction;
|
import org.hibernate.dialect.function.SQLFunction;
|
||||||
|
@ -459,6 +462,9 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement
|
||||||
@Override
|
@Override
|
||||||
public SessionFactory build() {
|
public SessionFactory build() {
|
||||||
metadata.validate();
|
metadata.validate();
|
||||||
|
final StandardServiceRegistry serviceRegistry = metadata.getMetadataBuildingOptions().getServiceRegistry();
|
||||||
|
BytecodeProvider bytecodeProvider = serviceRegistry.getService( BytecodeProvider.class );
|
||||||
|
addSessionFactoryObservers( new SessionFactoryObserverForBytecodeEnhancer( bytecodeProvider ) );
|
||||||
return new SessionFactoryImpl( metadata, buildSessionFactoryOptions() );
|
return new SessionFactoryImpl( metadata, buildSessionFactoryOptions() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -159,7 +159,7 @@ public final class ByteBuddyState {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wipes out all known caches used by ByteBuddy. This implies it might trigger the need
|
* 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
|
* multiple SessionFactory instances, but at least ensures we cleanup anything which is no
|
||||||
* longer needed after a SessionFactory close.
|
* longer needed after a SessionFactory close.
|
||||||
* The assumption is that closing SessionFactories is a rare event; in this perspective the cost
|
* The assumption is that closing SessionFactories is a rare event; in this perspective the cost
|
||||||
|
|
|
@ -753,8 +753,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
* @throws HibernateException
|
* @throws HibernateException
|
||||||
*/
|
*/
|
||||||
public void close() 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) {
|
synchronized (this) {
|
||||||
if ( isClosed ) {
|
if ( isClosed ) {
|
||||||
if ( getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) {
|
if ( getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) {
|
||||||
|
|
Loading…
Reference in New Issue