this my code below in my controller even though i pass a key which is valid i always get null as a result.Can someone tell me why is this happening .below is my repository ,controller and domain class
public interface AbcRepository extends JpaRepository<ForgotPasswordToken, int> {
Abc findByHashKey(String hashKey);
Abc findByUser(User user);
}
Mapping:
@RequestMapping(value = "/validateKey/{hashKey}", method = RequestMethod.GET)
public ResponseEntity validateKey(@PathVariable String hashKey) {
Abc abc = AbcRepository.findByHashKey(hashKey);
if (abc == null) {
return ResponseEntity.badRequest().body("Invalid key");
}
return ResponseEntity.ok().body(abc.getUser());
}
Entity:
@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();
}
}