mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 16:44:57 +00:00
HHH-12141 - SQL insert in stateless session causes javax.persistence.TransactionRequiredException
This commit is contained in:
parent
d2866620f2
commit
0ba1c4a2f3
@ -67,8 +67,11 @@ public void setInternalFetchProfile(String internalFetchProfile) {
|
||||
|
||||
private PersistenceContext temporaryPersistenceContext = new StatefulPersistenceContext( this );
|
||||
|
||||
private boolean connectionProvided;
|
||||
|
||||
StatelessSessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
|
||||
super( factory, options );
|
||||
connectionProvided = options.getConnection() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -648,6 +651,11 @@ public void afterTransactionCompletion(boolean successful, boolean delayed) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTransactionInProgress() {
|
||||
return connectionProvided || super.isTransactionInProgress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flushBeforeTransactionCompletion() {
|
||||
boolean flush = false;
|
||||
|
@ -8,14 +8,17 @@
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
@ -166,5 +169,17 @@ public void testRefresh() {
|
||||
ss.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-12141" )
|
||||
public void testInsertInStatelessSession() throws Exception {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
session.doWork( connection -> {
|
||||
StatelessSession sls = sessionFactory().openStatelessSession(connection);
|
||||
NativeQuery q = sls.createNativeQuery( "INSERT INTO paper (color) values ('red')");
|
||||
q.executeUpdate();
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user