HHH-13663 Method setHibernateFlushMode not callable without an active transaction on threadbound Sessions

This commit is contained in:
mimmoz81 2019-10-11 10:12:34 +02:00 committed by Sanne Grinovero
parent 9d6463eab6
commit 26edb2863f
2 changed files with 38 additions and 0 deletions

View File

@ -332,6 +332,7 @@ public class ThreadLocalSessionContext extends AbstractCurrentSessionContext {
|| "getTransaction".equals( methodName ) || "getTransaction".equals( methodName )
|| "isTransactionInProgress".equals( methodName ) || "isTransactionInProgress".equals( methodName )
|| "setFlushMode".equals( methodName ) || "setFlushMode".equals( methodName )
|| "setHibernateFlushMode".equals( methodName )
|| "getFactory".equals( methodName ) || "getFactory".equals( methodName )
|| "getSessionFactory".equals( methodName ) || "getSessionFactory".equals( methodName )
|| "getTenantIdentifier".equals( methodName ) ) { || "getTenantIdentifier".equals( methodName ) ) {

View File

@ -0,0 +1,37 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.test.flush;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
/**
* Test for issue https://hibernate.atlassian.net/browse/HHH-13663
*
* @author Luca Domenichini
*/
@TestForIssue(jiraKey = "HHH-13663")
public class TestHibernateFlushModeOnThreadLocalInactiveTransaction extends BaseCoreFunctionalTestCase {
@Override
protected void configure(Configuration configuration) {
configuration.setProperty(AvailableSettings.CURRENT_SESSION_CONTEXT_CLASS, "thread");
}
@Test
public void testHibernateFlushModeOnInactiveTransaction() {
Session s = openSession();
//s.setFlushMode(FlushMode.AUTO); // this does not throw (API is deprecated)
s.setHibernateFlushMode(FlushMode.AUTO); // this should not throw even within an inactive transaction
}
}