Java spring boot jpa存储库接口始终返回null

Java spring boot jpa存储库接口始终返回null,java,jpa,spring-boot,repository,Java,Jpa,Spring Boot,Repository,这是我在我的控制器下面的代码,即使我传递了一个有效的密钥,结果总是为空。有人能告诉我为什么会发生这种情况吗。下面是我的存储库、控制器和域类 public interface AbcRepository extends JpaRepository<ForgotPasswordToken, int> { Abc findByHashKey(String hashKey); Abc findByUser(User user); } 实体: @Entity @Data pu

这是我在我的控制器下面的代码,即使我传递了一个有效的密钥,结果总是为空。有人能告诉我为什么会发生这种情况吗。下面是我的存储库、控制器和域类

public interface AbcRepository extends JpaRepository<ForgotPasswordToken, int> {
    Abc findByHashKey(String hashKey);
    Abc findByUser(User user);
}
实体:

@Entity
@Data
public class Abc {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @OneToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id")
    private User user;

    private String hashKey;

    private String email;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createdAt;

    @PrePersist
    public void onCreate() {
        this.createdAt = new Date();
    }

}

存储库和ABC类中有不同类型的主键

你应该改变

JpaRepository<ForgotPasswordToken, int> 
建议使用对象类型作为JPA@Id而不是原语。因此,将
long
更改为
long


请参见

您的存储库正在返回
放弃密码令牌
not
Abc
,并且您的键是
long
not
int
,或者,您没有任何实体匹配您的标准。我尝试了long,但仍然得到相同的结果。我在任何地方都使用ForgotPasswordToken而不是Abc。很抱歉,在这里复制代码时出错。我想为ForgotPasswordToken使用别名,因此使用的Abci在我的dbIs
Abc
中是否有匹配的实体为空,或者您的存储库是否为空?
JpaRepository<ForgotPasswordToken, int> 
JpaRepository<ForgotPasswordToken, Long>
private Long id;