错误查找对象 Spring JPA:“通过持久属性的反射访问字段时出错”

我有以下课程:


@Entity(name = "focusoc_orbit")

@Data

public class OrbitAdapter extends Adapter{


  @Id

  private String              id;


  ...


  public String getId() {

    return id;

  }


  public void setId(String id) {

    this.id = id;

  }


  ...


}

和,


@Entity(name = "focusoc_conjunction")

@Data

public class ConjunctionAdapter extends Adapter {


  @Id

  @GeneratedValue(strategy = GenerationType.IDENTITY)

  private Long         id;


  @ManyToOne

  @JoinColumn(name = "target_id")

  private OrbitAdapter target;


  @ManyToOne

  @JoinColumn(name = "chaser_id")

  private OrbitAdapter chaser;


  ...

  public OrbitAdapter getTarget(){

    return target;

  }

  public void setTarget(OrbitAdapter target){

    this.target = target;

  }

  public String getChaserId(){

    return chaserId;

  }

  public void setChaser(OrbitAdapter chaser){

    this.chaser = chaser;

  }


  ...


}

我还定义了存储库:


public interface ConjunctionRepository extends PagingAndSortingRepository<ConjunctionAdapter, Long> {

  public ConjunctionAdapter findByTargetAndChaserAndTimeOfCloseApproach(String target, String chaser, Date timeOfCloseApproach);

}

当我尝试拨打电话时,


ConjunctionAdapter c = conjunctionRepository.findByTargetAndChaserAndTimeOfCloseApproach(targetId, chaserId, timeOfCloseApproach());

它返回错误:


org.hibernate.property.access.spi.PropertyAccessException:通过持久属性 [gcs.fds.focusoc.adapter.OrbitAdapter# 的反射访问字段 [private java.lang.String gcs.fds.focusoc.adapter.OrbitAdapter.id] 时出错id]:02035A”


我尝试了很多不同的解决方案,但发现它对我不起作用。有什么帮助吗?


小唯快跑啊
浏览 98回答 1
1回答

元芳怎么了

我解决了!将@Table类的注释@Data更改为表名。所以,@Entity@Table(name = "focusoc_orbit")public class OrbitAdapter extends Adapter{&nbsp; @Id&nbsp; private String&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id;&nbsp; ...&nbsp; public String getId() {&nbsp; &nbsp; return id;&nbsp; }&nbsp; public void setId(String id) {&nbsp; &nbsp; this.id = id;&nbsp; }&nbsp; ...}和,@Entity@Table(name = "focusoc_conjunction")public class ConjunctionAdapter extends Adapter {&nbsp; @Id&nbsp; @GeneratedValue(strategy = GenerationType.IDENTITY)&nbsp; private Long&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;id;&nbsp; @ManyToOne&nbsp; @JoinColumn(name = "target_id")&nbsp; private OrbitAdapter target;&nbsp; @ManyToOne&nbsp; @JoinColumn(name = "chaser_id")&nbsp; private OrbitAdapter chaser;&nbsp; ...&nbsp; public OrbitAdapter getTarget(){&nbsp; &nbsp; return target;&nbsp; }&nbsp; public void setTarget(OrbitAdapter target){&nbsp; &nbsp; this.target = target;&nbsp; }&nbsp; public String getChaserId(){&nbsp; &nbsp; return chaserId;&nbsp; }&nbsp; public void setChaser(OrbitAdapter chaser){&nbsp; &nbsp; this.chaser = chaser;&nbsp; }&nbsp; ...}这样做会返回错误,java.lang.IllegalArgumentException:参数值 [02035A] 与预期类型不匹配 [gcs.fds.focusoc.adapter.OrbitAdapter (n/a)]所以我在Repository中添加了注释@Query来指定必须在数据库中搜索哪些内容,public interface ConjunctionRepository extends PagingAndSortingRepository<ConjunctionAdapter, Long> {&nbsp; @Query("SELECT c FROM ConjunctionAdapter c WHERE c.target.id = :target AND c.chaser.id = :chaser AND c.timeOfCloseApproach = :timeOfCloseApproach")&nbsp; public ConjunctionAdapter findByTargetAndChaserAndTimeOfCloseApproach(String target, String chaser, Date timeOfCloseApproach);}并解决了!
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java