HHH-13677 make org.hibernate.flushMode config take effect

This commit is contained in:
Nathan Xu 2019-12-12 19:29:07 -05:00 committed by Andrea Boriero
parent a6934467f7
commit 9d2ac546f3
2 changed files with 62 additions and 0 deletions

View File

@ -256,6 +256,8 @@ public class SessionImpl
// NOTE : pulse() already handles auto-join-ability correctly
getTransactionCoordinator().pulse();
getSession().setHibernateFlushMode( ConfigurationHelper.getFlushMode( getSessionProperty( AvailableSettings.FLUSH_MODE ), FlushMode.AUTO ) );
if ( log.isTraceEnabled() ) {
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );
}

View File

@ -0,0 +1,60 @@
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.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.junit.After;
import org.junit.Before;
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 Nathan Xu
*/
@TestForIssue( jiraKey = "HHH-13677" )
@RunWith( Parameterized.class )
public class FlushModeConfigTest {
@Parameters
public static FlushMode[] parameters() {
return FlushMode.values();
}
@Parameter
public FlushMode flushMode;
private StandardServiceRegistryImpl serviceRegistry;
@Before
public void setUp() {
serviceRegistry = (StandardServiceRegistryImpl) new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.FLUSH_MODE, flushMode.name() )
.build();
}
@Test
public void testFlushModeSettingTakingEffect() {
try ( final SessionFactory sessionFactory = new MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory() ) {
try ( final Session session = sessionFactory.openSession() ) {
assertEquals( flushMode, session.getHibernateFlushMode() );
}
}
}
@After
public void tearDown() {
serviceRegistry.destroy();
}
}