HHH-13974 FlushMode set through SessionBuilder was never applied
This commit is contained in:
parent
0ee25a416d
commit
d19bb536ef
|
@ -1162,9 +1162,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
|
||||||
this.statementInspector = sessionFactoryOptions.getStatementInspector();
|
this.statementInspector = sessionFactoryOptions.getStatementInspector();
|
||||||
this.connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
|
this.connectionHandlingMode = sessionFactoryOptions.getPhysicalConnectionHandlingMode();
|
||||||
this.autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
|
this.autoClose = sessionFactoryOptions.isAutoCloseSessionEnabled();
|
||||||
this.flushMode = sessionFactoryOptions.isFlushBeforeCompletionEnabled()
|
|
||||||
? FlushMode.AUTO
|
|
||||||
: FlushMode.MANUAL;
|
|
||||||
|
|
||||||
final CurrentTenantIdentifierResolver currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver();
|
final CurrentTenantIdentifierResolver currentTenantIdentifierResolver = sessionFactory.getCurrentTenantIdentifierResolver();
|
||||||
if ( currentTenantIdentifierResolver != null ) {
|
if ( currentTenantIdentifierResolver != null ) {
|
||||||
|
|
|
@ -255,6 +255,8 @@ public class SessionImpl
|
||||||
// NOTE : pulse() already handles auto-join-ability correctly
|
// NOTE : pulse() already handles auto-join-ability correctly
|
||||||
getTransactionCoordinator().pulse();
|
getTransactionCoordinator().pulse();
|
||||||
|
|
||||||
|
// do not override explicitly set flush mode ( SessionBuilder#flushMode() )
|
||||||
|
if ( getHibernateFlushMode() == null ) {
|
||||||
final FlushMode initialMode;
|
final FlushMode initialMode;
|
||||||
if ( this.properties == null ) {
|
if ( this.properties == null ) {
|
||||||
initialMode = fastSessionServices.initialSessionFlushMode;
|
initialMode = fastSessionServices.initialSessionFlushMode;
|
||||||
|
@ -263,6 +265,7 @@ public class SessionImpl
|
||||||
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
|
initialMode = ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO );
|
||||||
}
|
}
|
||||||
getSession().setHibernateFlushMode( initialMode );
|
getSession().setHibernateFlushMode( initialMode );
|
||||||
|
}
|
||||||
|
|
||||||
if ( log.isTraceEnabled() ) {
|
if ( log.isTraceEnabled() ) {
|
||||||
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );
|
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );
|
||||||
|
|
|
@ -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() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue