Spring data jpa hibernate: query exception java.sql.SQLException: Column 'column name' not found

Accidental error using spring boot, jap, hibernate:

java.sql.SQLException: Column ‘列名’ not found:

This sentence means: Can't find this column
Why does this problem occur?
Reason: We aliased .

The database field is underlined: el_empno
is like this in @Query: (value = "select el_empno as empno ...")
OK, the exception is here: java.sql.SQLException: Column 'column name' not found

When using spring boot again, when using a similar statement in ...Repository:
@Query(value = "SELECT column name 1, column name 2, ... column name n FROM table name", nativeQuery= true)
If you are like this: @Query (value = "SELECT column name 1 AS alias 1, column name 2 AS alias 2, ... column name n AS alias N FROM table name", nativeQuery= true)
will report an error: java.sql.SQLException: Column 'column name' not found

When we use SQL statements, all fields in the table are written out. If there are too many, use *. If there are not many, write them out one by one. Remember not to add aliases
. SQLException: Column 'column name' not found

Avoid this error:

  1. Do not alias query fields
  2. Write out all the fields in the table to be queried, whether you need the field or not, write in full
  3. OK, problem solved. . .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325808807&siteId=291194637