Skip to content

JSqlParserQueryEnhancer errors with INSERT statements #2593

Closed
@stulscott

Description

@stulscott

When starting a Spring Boot application with >= 2.7.0 the application fails to start if it has native INSERT queries defined in JpaRepositories. The error is:

java.lang.ClassCastException: class net.sf.jsqlparser.statement.insert.Insert cannot be cast to class net.sf.jsqlparser.statement.select.Select

For example, any JpaRepository with the following will error and prevent the application from starting:

    @Modifying
    @Query(value = "INSERT INTO FOO(A) VALUES('A')", nativeQuery = true)
    void insertFoo();

detectParsedType() appears to neglect the Insert statement type:

			Statement statement = CCJSqlParserUtil.parse(this.query.getQueryString());

			if (statement instanceof Update) {
				return ParsedType.UPDATE;
			} else if (statement instanceof Delete) {
				return ParsedType.DELETE;
			} else if (statement instanceof Select) {
				return ParsedType.SELECT;
			} else {
				return ParsedType.SELECT;
			}

Metadata

Metadata

Assignees

Labels

in: query-parserEverything related to parsing JPQL or SQLtype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions