Skip to content

Commit

Permalink
HHH-13677 make org.hibernate.flushMode config take effect
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanQingyangXu authored and dreab8 committed Jan 28, 2020
1 parent a693446 commit 9d2ac54
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
Expand Up @@ -256,6 +256,8 @@ public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
// 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() );
}
Expand Down
@@ -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();
}

}

0 comments on commit 9d2ac54

Please sign in to comment.