spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.98k stars 1.41k forks source link

IDE reports unexpected query tokens on `@Query(INSERT …` #3498

Closed 3066097899 closed 3 months ago

3066097899 commented 3 months ago
1 2

Why does the "Insert unexpected" issue occur during the insert operation when I configure the custom operation database method in JPA? SQL statements, regardless of capitalization, cannot solve it

mp911de commented 3 months ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

3066097899 commented 3 months ago

study_jpa_query.zip In this project, I am learning to use a custom sql method in the JPA operating database. When I define an "INSERT" method, the "INSERT unexpected" problem occurs. I use the "@ Query annotation" where the problem occurs. After I use mybaties, I call the @ Insert annotation in mybaties to solve the problem. How can I solve the problem without using mybaties

In this project, I am learning to use a custom sql method in the JPA operating database. When I define an "INSERT" method, the "INSERT unexpected" problem occurs. I use the "@ Query annotation" where the problem occurs. After I use mybaties, I call the @ Insert annotation in mybaties to solve the problem. How can I solve the problem without using mybaties

mp911de commented 3 months ago

The code is a pretty wild mix of annotations. Generally speaking, Spring Data isn't raising any IDE errors, that's the responsibility of IDE plugin authors. For any modifying queries, please add @Modifying to indicate that the query is running insert/update/delete statements. Also, the @Query("INSERT INTO …) query is missing nativeQuery = true.