Skip to content

Commit 8cce172

Browse files
committed
fix: Adjust the transaction implementation method in JdbcChatMemoryRepository.
Signed-off-by: Sun Yuhan <[email protected]>
1 parent 0a78b48 commit 8cce172

File tree

1 file changed

+4
-4
lines changed
  • memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc

1 file changed

+4
-4
lines changed

memory/repository/spring-ai-model-chat-memory-repository-jdbc/src/main/java/org/springframework/ai/chat/memory/repository/jdbc/JdbcChatMemoryRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ public class JdbcChatMemoryRepository implements ChatMemoryRepository {
5050

5151
private final JdbcTemplate jdbcTemplate;
5252

53+
private final TransactionTemplate transactionTemplate;
54+
5355
private final JdbcChatMemoryRepositoryDialect dialect;
5456

5557
private JdbcChatMemoryRepository(JdbcTemplate jdbcTemplate, JdbcChatMemoryRepositoryDialect dialect) {
5658
Assert.notNull(jdbcTemplate, "jdbcTemplate cannot be null");
5759
Assert.notNull(dialect, "dialect cannot be null");
60+
Assert.notNull(jdbcTemplate.getDataSource(), "dataSource can not be null");
5861
this.jdbcTemplate = jdbcTemplate;
5962
this.dialect = dialect;
63+
transactionTemplate = new TransactionTemplate(new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
6064
}
6165

6266
@Override
@@ -83,10 +87,6 @@ public void saveAll(String conversationId, List<Message> messages) {
8387
Assert.notNull(messages, "messages cannot be null");
8488
Assert.noNullElements(messages, "messages cannot contain null elements");
8589

86-
Assert.notNull(jdbcTemplate.getDataSource(), "dataSource can not be null");
87-
TransactionTemplate transactionTemplate = new TransactionTemplate(
88-
new DataSourceTransactionManager(jdbcTemplate.getDataSource()));
89-
9090
transactionTemplate.execute(status -> {
9191
try {
9292
deleteByConversationId(conversationId);

0 commit comments

Comments
 (0)