Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-13677 Make org.hibernate.flushMode config take effect #3144

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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 ) );

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sanne should we add the FlushMode to the FastSessionServices?

Copy link
Contributor Author

@NathanQingyangXu NathanQingyangXu Jan 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, FastSessionServices contains FlushMode default value. If you drill down the getSessionProperty() you can see it will look up in FastSessionServices by default. The FlushMode.AUTO above will never take effect for FastSessionServices should have returned a non-null value for AvailableSettings.FLUSH_MODE :
Screen Shot 2020-01-27 at 5 34 12 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, looks good. Is something not working as expected @dreab8 ? Feel free to add tests :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed that getSessionProperty takes the value from the FastSessionServices

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum both ConfigurationHelper#getFlushMode and the getSessionProperty methods are rather slow though. I see what @dreab8 meant now, I will add an additional fix to this.

if ( log.isTraceEnabled() ) {
log.tracef( "Opened Session [%s] at timestamp: %s", getSessionIdentifier(), getTimestamp() );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}

}