[英]Spring Data JPA: How to fix NullPointerException in findById method of CrudRepository?
[英]How to properly use findBySomeOtherId not findById in Spring data jpa?
我正在使用 spring 数据 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)]\r\n\tat org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible
这是采访状态class
@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);
}
我想要基于 interviewId 的记录。 我已经可以在主键的基础上得到它,但我想要它基于面试 ID,我在 interviewStatus 表中有 interviewId 列。
请使用这个InterviewStatus findByInterviewId(Interviews interviewId);
通过运行Interviews findById(Long id)
获得 interviewId。
由于数据类型冲突,您可以将预期数据类型作为参数传入。 所以期待采访不是 Integer,但你有 integer。 在这种情况下,您使用 integer 获得采访,然后将获得的采访作为参数传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.