HHH-13974 FlushMode set through SessionBuilder was never applied

This commit is contained in:
Michael Spahn 2020-04-23 16:27:26 +02:00 committed by Sanne Grinovero
parent 0ee25a416d
commit d19bb536ef
3 changed files with 51 additions and 10 deletions

View File

@ -1162,9 +1162,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
this.statementInspector = sessionFactoryOptions.getStatementInspector();
this.connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
this.autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
this.flushMode = sessionFactoryOptions.isFlushBeforeCompletionEnabled()
? FlushMode.AUTO
: FlushMode.MANUAL;
final CurrentTenantIdentifierResolver currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver();
if ( currentTenantIdentifierResolver != null ) {

View File

@ -255,14 +255,17 @@ public class SessionImpl
// NOTE : pulse() already handles auto-join-ability correctly
getTransactionCoordinator().pulse();
final FlushMode initialMode;
if ( this.properties == null ) {
initialMode = fastSessionServices.initialSessionFlushMode;
// do not override explicitly set flush mode ( SessionBuilder#flushMode() )
if ( getHibernateFlushMode() == null ) {
final FlushMode initialMode;
if ( this.properties == null ) {
initialMode = fastSessionServices.initialSessionFlushMode;
}
else {
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
}
getSession().setHibernateFlushMode( initialMode );
}
else {
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
}
getSession().setHibernateFlushMode( initialMode );
if ( log.isTraceEnabled() ) {
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );

View File

@ -0,0 +1,41 @@
package org.hibernate.internal;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.testing.TestForIssue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
import static org.junit.Assert.assertEquals;
/**
* @author Michael Spahn
*/
@TestForIssue(jiraKey = "HHH-13974")
@RunWith(Parameterized.class)
public class SessionBuilderFlushModeTest {
@Parameters
public static FlushMode[] parameters() {
return FlushMode.values();
}
@Parameter
public FlushMode flushMode;
@Test
public void testFlushMode() {
try (final SessionFactory sessionFactory = new MetadataSources( new StandardServiceRegistryBuilder().build() ).buildMetadata().buildSessionFactory()) {
try (final Session session = sessionFactory.withOptions().flushMode( flushMode ).openSession()) {
assertEquals( flushMode, session.getHibernateFlushMode() );
}
}
}
}