mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#19 - java.lang.IllegalStateException: Transaction is Inactive ... when using Ebean transactions with Ebean's Spring transaction manager
This commit is contained in:
@@ -71,12 +71,11 @@ public class SpringJdbcTransactionManager implements ExternalTransactionManager
|
||||
if (holder == null || !holder.isSynchronizedWithTransaction()) {
|
||||
// no current Spring transaction
|
||||
SpiTransaction currentEbeanTransaction = transactionManager.getInScope();
|
||||
if (currentEbeanTransaction != null && currentEbeanTransaction.isActive()) { // this is unexpected
|
||||
log.warn("No current Spring transaction BUT using current Ebean one {}", currentEbeanTransaction.getId());
|
||||
if (currentEbeanTransaction == null || !currentEbeanTransaction.isActive()) {
|
||||
return null;
|
||||
} else {
|
||||
log.trace("No current Spring transaction");
|
||||
return currentEbeanTransaction;
|
||||
}
|
||||
return currentEbeanTransaction;
|
||||
}
|
||||
|
||||
SpringTxnListener springTxnLister = getSpringTxnListener();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.example;
|
||||
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
@@ -34,6 +36,27 @@ public class EbeanSpringModuleTest {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test app.
|
||||
*/
|
||||
@Test
|
||||
public void testInactiveTransaction() {
|
||||
|
||||
Transaction transaction = Ebean.beginTransaction();
|
||||
long id;
|
||||
try {
|
||||
User user = new User();
|
||||
user.setName("save with txn 1");
|
||||
Ebean.save(user);
|
||||
transaction.commit();
|
||||
id = user.getOid();
|
||||
} finally {
|
||||
// don't end the transaction ...
|
||||
//transaction.end();
|
||||
}
|
||||
|
||||
Ebean.delete(User.class, id);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBatchInsert() {
|
||||
|
||||
Reference in New Issue
Block a user