Skip to content

Commit 7b7ef15

Browse files
michiel.hendriksSanne
authored andcommitted
HHH-13936 Call pulseTransactionCoordinator before checking for transaction in flush()
(cherry picked from commit 585ca8e)
1 parent 9b2a960 commit 7b7ef15

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1459,8 +1459,8 @@ public void flush() throws HibernateException {
14591459
}
14601460

14611461
private void doFlush() {
1462-
checkTransactionNeededForUpdateOperation();
14631462
pulseTransactionCoordinator();
1463+
checkTransactionNeededForUpdateOperation();
14641464

14651465
try {
14661466
if ( persistenceContext.getCascadeLevel() > 0 ) {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.flush;
8+
9+
import java.util.Map;
10+
11+
import javax.persistence.TransactionRequiredException;
12+
13+
import org.hibernate.Session;
14+
import org.hibernate.cfg.AvailableSettings;
15+
import org.junit.Assert;
16+
import org.junit.Test;
17+
18+
import org.hibernate.testing.TestForIssue;
19+
import org.hibernate.testing.jta.TestingJtaBootstrap;
20+
import org.hibernate.testing.jta.TestingJtaPlatformImpl;
21+
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
22+
23+
/**
24+
* @author Michiel Hendriks
25+
*/
26+
@TestForIssue(jiraKey = "HHH-13936")
27+
public class TestFlushJoinTransaction extends BaseNonConfigCoreFunctionalTestCase {
28+
29+
@Override
30+
protected void addSettings(Map settings) {
31+
super.addSettings( settings );
32+
TestingJtaBootstrap.prepare( settings );
33+
settings.put( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jta" );
34+
}
35+
36+
@Test
37+
public void testFlush() throws Exception {
38+
Session session = openSession();
39+
try {
40+
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
41+
session.flush();
42+
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
43+
}
44+
catch (TransactionRequiredException e) {
45+
Assert.fail("No TransactionRequiredException expected.");
46+
}
47+
finally {
48+
session.close();
49+
}
50+
}
51+
52+
@Test
53+
public void testIsConnectedFlush() throws Exception {
54+
Session session = openSession();
55+
try {
56+
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
57+
session.isConnected();
58+
session.flush();
59+
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().commit();
60+
}
61+
catch (TransactionRequiredException e) {
62+
Assert.fail("No TransactionRequiredException expected.");
63+
}
64+
finally {
65+
session.close();
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)