1 回答
TA贡献1798条经验 获得超7个赞
我解决了!
将@Table类的注释@Data更改为表名。所以,
@Entity
@Table(name = "focusoc_orbit")
public class OrbitAdapter extends Adapter{
@Id
private String id;
...
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
...
}
和,
@Entity
@Table(name = "focusoc_conjunction")
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;
}
...
}
这样做会返回错误,
java.lang.IllegalArgumentException:参数值 [02035A] 与预期类型不匹配 [gcs.fds.focusoc.adapter.OrbitAdapter (n/a)]
所以我在Repository中添加了注释@Query来指定必须在数据库中搜索哪些内容,
public interface ConjunctionRepository extends PagingAndSortingRepository<ConjunctionAdapter, Long> {
@Query("SELECT c FROM ConjunctionAdapter c WHERE c.target.id = :target AND c.chaser.id = :chaser AND c.timeOfCloseApproach = :timeOfCloseApproach")
public ConjunctionAdapter findByTargetAndChaserAndTimeOfCloseApproach(String target, String chaser, Date timeOfCloseApproach);
}
并解决了!
添加回答
举报