我正在使用这种方法

@Query(value = "SELECT p.id, p.picture, p.name, p.age, p.info, p.city, p.state, p.status\n" +
        "FROM owner_pet as op\n" +
        "INNER JOIN lost_pet as p on op.id_pet =?1\n" +
        "WHERE op.id_owner =?1", nativeQuery = true)
List<LostPetEntity> find(Integer id);


当我在MySQL工作台上使用此查询时,它给我带来了LostPetEntity表
java - 尝试使用Hibernate进行SELECT时发生ConverterNotFoundException-LMLPHP
 但在我的spring应用程序中,它使我放弃了此异常:


  Servlet [dispatcherServlet]在带有路径的上下文中的Servlet.service()
  []引发异常[请求处理失败;嵌套异常为
  org.springframework.core.convert.ConversionFailedException:失败
  从类型[java.lang.Object []]转换为类型
  [fearx.projects.animal.finder.api.entity.LostPetEntity]的值为“ {1,
  Dogola,1,NovaUnião,/ r / ban,RO,NOTCHICED,默认值}’;嵌套的
  例外是
  org.springframework.core.convert.ConverterNotFoundException:否
  发现可以将类型[java.lang.Integer]转换为
  键入[fearx.projects.animal.finder.api.entity.LostPetEntity]]与
  根本原因
  
  org.springframework.core.convert.ConverterNotFoundException:否
  发现可以将类型[java.lang.Integer]转换为
  类型[fearx.projects.animal.finder.api.entity.LostPetEntity]




LostPetEntity.class:

package fearx.projects.animal.finder.api.entity;

import fearx.projects.animal.finder.api.pets.PetDTO;
import fearx.projects.animal.finder.api.pets.Status;
import lombok.Data;

import javax.persistence.*;

@Entity(name = "lost_pet")
@Data
public class LostPetEntity {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Integer id;
    @Column
    private String picture;
    @Column
    private String name;
    @Column
    private String age;
    @Column
    private String info;
    @Column
    private String city;
    @Column
    private String state;
    @Column
    private String status;

    public LostPetEntity(PetDTO dto) {
        this.picture = dto.getPicture();
        this.name = dto.getName();
        this.age = dto.getAge();
        this.info = dto.getInfo();
        this.city = dto.getCity();
        this.state = dto.getState();
        this.status = String.valueOf(Status.MISSING);
    }

    public LostPetEntity() {
    }
}


我能做什么?

最佳答案

将代码更改为此。

List<Object[]> find(Integer id);

08-07 04:01