Skip to content

RC1 ERROR:MysqlChatMemoryRepositoryDialect #3155

@lyxfn

Description

@lyxfn

Bug description
I upgraded Spring AI Version from 1.0.0-M7 to 1.0.0-RC1. Before that, I used a custom RedisChatMemory. I found that there is an implementation of JdbcChatMemory in the new version, so I decided to replace RedisChatMemory.

The getSelectMessagesSql() method of MysqlChatMemoryRepositoryDialect requires two parameters, conversation_id and limit, to be passed in, and there is no default value.

public class MysqlChatMemoryRepositoryDialect implements JdbcChatMemoryRepositoryDialect {

	@Override
	public String getSelectMessagesSql() {
		return "SELECT content, type FROM SPRING_AI_CHAT_MEMORY WHERE conversation_id = ? ORDER BY `timestamp` DESC LIMIT ?";
	}

However, the upper-level JdbcChatMemoryRepository.findByConversationId(String conversationId) only has one conversation_id parameter.

public class JdbcChatMemoryRepository implements ChatMemoryRepository
	@Override
	public List<Message> findByConversationId(String conversationId) {
		Assert.hasText(conversationId, "conversationId cannot be null or empty");
		return this.jdbcTemplate.query(dialect.getSelectMessagesSql(), new MessageRowMapper(), conversationId);
	}

so an Exception occurred after I initiated the call.

org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT content, type FROM SPRING_AI_CHAT_MEMORY WHERE conversation_id = ? ORDER BY `timestamp` DESC LIMIT ?]


Caused by: java.sql.SQLException: No value specified for parameter 2
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.19.jar:8.0.19]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.19.jar:8.0.19]

Has anyone else encountered this problem, or is there something wrong with my usage? Please help me solve this problem

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions