The problem of Spring Data Jpa Framework Custom query statement returning Custom entity

1. Due to the need to query the two code,name fields in the entity table, Baidu said that it can customize the query entity class, such as:

public class Entity implements Serializable(){
    String code ;
    String name ;
    ...
    public Entity (String code, String name) {
    super();
    this.code = code;
    this.name = name;
}
}

sql statement

@Query(value = "select new com.Vo.Entity(code,name) FROM user")
List<Entity> selectEntity();

in this way, the code and name fields in the user table of the database query can be automatically added to the entity entity, and the error is now protected as follows:

2018-08-31 18 nio-8080-exec-2 44br 45.113 DEBUG 8528--> [nio-8080-exec-2] [
org.hibernate.SQL]: select new com.Vo.Entity (code,name) FROM user
2018-08-31 18V 44V 45.448 WARN 8528-> [nio-8080-exec-2] [
o.h.engine.jdbc.spi.SqlExceptionHelper]: SQL Error: 923, SQLState:
42000 2018-08-31 18 ERROR 45.452 ERROR 8528--> [nio-8080-exec-2] [
o.h.engine.jdbc.spi.SqlExceptionHelper]: ORA-00923: did not find the required FROM keyword

Why can"t you find the From keyword when there is a from?

May.22,2021

select new com.Vo.Entity (u.code.u.name) FROM user u
that should be OK

Menu