You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose to support to propagate a savepoint operation via TransactionSynchronization.
Background
I'm the MyBatis's developer. Now, If application developer use the savepoint(=PROPAGATION_NESTED) feature together with MyBatis, If perform select statement after rollback a savepoint, an application may get the rolled back data from MyBatis's local cache.
I want to the opportunity for clearing local cache that hold on MyBatis module at savepoint operations(at roll backed mainly) for resolving potential problem.
packagecom.example;
importorg.apache.ibatis.annotations.Insert;
importorg.apache.ibatis.annotations.Mapper;
importorg.apache.ibatis.annotations.Select;
importorg.apache.ibatis.annotations.Update;
importorg.assertj.core.api.Assertions;
importorg.junit.jupiter.api.Test;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.boot.test.context.SpringBootTest;
importorg.springframework.transaction.PlatformTransactionManager;
importorg.springframework.transaction.TransactionDefinition;
importorg.springframework.transaction.support.DefaultTransactionDefinition;
importorg.springframework.transaction.support.TransactionOperations;
importorg.springframework.transaction.support.TransactionTemplate;
@SpringBootTestclassMybatisSpringGh785ApplicationTests {
@AutowiredMessageMappermapper;
@AutowiredPlatformTransactionManagertransactionManager;
@TestvoidcontextLoads() {
// TransactionOperations for standard JDBC TransactionDefaultTransactionDefinitiontxDef = newDefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionOperationstxOperations = newTransactionTemplate(transactionManager, txDef);
// TransactionOperations for JDBC savepoint TransactionDefaultTransactionDefinitionsavepointTxDef = newDefaultTransactionDefinition(
TransactionDefinition.PROPAGATION_NESTED);
TransactionOperationssavepointTxOperations = newTransactionTemplate(transactionManager, savepointTxDef);
// Insert test datatxOperations.executeWithoutResult(s -> {
mapper.insert(newMessage(1, "Hello!"));
});
// Do TestingtxOperations.executeWithoutResult(txStatus -> {
// Select latest message and save to local cacheMessagemessageBefore = mapper.select(1);
// Execute processing on savepoint transactionsavepointTxOperations.executeWithoutResult(savepointTxStatus -> {
// Update and clear local cachemapper.update(newMessage(1, "Hello World!!"));
// Select latest message and save to local cachemapper.select(1);
// Mark to rollback savepointsavepointTxStatus.setRollbackOnly();
});
// Select latest message but does not return latest message from database because does not clear local cache when savepoint rollbackMessagemessageAfter = mapper.select(1);
Assertions.assertThat(messageAfter.message()).isEqualTo(messageBefore.message()); // Failed assertion
});
}
recordMessage(intid, Stringmessage) {
}
@MapperinterfaceMessageMapper {
@Select("SELECT id, message FROM messages WHERE id = #{id}")
Messageselect(intid);
@Insert("INSERT INTO messages (id, message) VALUES(#{id}, #{message})")
voidinsert(Messagemessage);
@Update("UPDATE messages SET message = #{message} WHERE id = #{id}")
voidupdate(Messagemessage);
}
}
CREATETABLEmessages
(
id bigintprimary key,
message varchar(256) not null
);
The text was updated successfully, but these errors were encountered:
jhoeller
changed the title
Support to propagate a savepoint operations via TransactionSynchronization
Support to propagate a savepoint operation via TransactionSynchronization
Feb 15, 2024
I propose to support to propagate a savepoint operation via
TransactionSynchronization
.Background
I'm the MyBatis's developer. Now, If application developer use the savepoint(=
PROPAGATION_NESTED
) feature together with MyBatis, If perform select statement after rollback a savepoint, an application may get the rolled back data from MyBatis's local cache.I want to the opportunity for clearing local cache that hold on MyBatis module at savepoint operations(at roll backed mainly) for resolving potential problem.
Related Issues
Example Testing Code
The text was updated successfully, but these errors were encountered: