如何在 Spring 数据 jpa 中正确使用 findBySomeOtherId 而不是 findById?



我正在用 spring data jpa(MYSQL( 做一个 Spring 引导项目 当我到达这个终点时http://localhost:8080/admin/interviews/101我收到此错误

{
"timestamp": "2019-10-11T13:45:37.111+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Parameter value [101] did not match expected type [com.yash.arci.model.Interviews (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [101] did not match expected type [com.yash.arci.model.Interviews (n/a)]",
"trace": "org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [101] did not match expected type [com.yash.arci.model.Interviews (n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [101] did not match expected type [com.yash.arci.model.Interviews (n/a)]rntat org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible

这是面试状态类

@Entity
@Table(name ="interview_status" )
public class InterviewStatus implements Serializable {

private static final long serialVersionUID = -6353284727527331855L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name ="interviewId",insertable = false, updatable = false)
private Interviews interviewId;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name ="statusId",insertable = false, updatable = false)
private Status statusId;
..........
}

@Repository
public interface InterviewStatusRepository extends 
JpaRepository<InterviewStatus, Integer> {
InterviewStatus findByInterviewId(Integer interviewId);
}

我想要基于访谈ID的记录。我已经可以在主键的基础上获得,但我希望它基于采访 ID,我在面试状态表中有 interviewId 列。

请使用此InterviewStatus findByInterviewId(Interviews interviewId);,其中通过运行Interviews findById(Long id)来获取 interviewId 。

由于数据类型冲突,可以将预期的数据类型作为参数传入。 所以它期待的是采访而不是整数,但你有整数。 在这种情况下,您可以使用整数获取采访,然后将获取的采访作为参数传递。

相关内容

  • 没有找到相关文章

最新更新