I am trying to retrieve a Ratings class object. But userId and answer_id are foreign keys. Therefore they are join Columns.
@Query("SELECT r FROM Ratings r WHERE r.userId = ?1 AND r.answer_id = ?2")
public Ratings searchObject(Long userId,Long answerId);
public class Ratings {
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "userId")
private User user;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "answer_id")
private Answer answer;
//GETTERS AND SETTETRS
}
This error has occurred. when I tried to retrieve ratings object:
Caused by: org.hibernate.QueryException: could not resolve property: userId of: com.smartedulanka.finalyearproject.datalayer.entity.Ratings
How do I fix this issue?
CodePudding user response:
You need to decide if you want to use a HQL (recommended) or a native query:
HQL:
@Query("FROM Ratings r WHERE r.user.id = ?1 AND r.answer.id = ?2")
SQL:
@Query(nativeQuery=true, value="SELECT r FROM Ratings r WHERE r.userId = ?1 AND r.answer_id = ?2")