Reputation:
I have a problem with a named query but I don't get it why it doesn't work.
This is how I define the queries:
@NamedQueries({
@NamedQuery(
name = Rating.FIND_ALL,
query = "from Rating"
),
@NamedQuery(
name = "getUserRatings",
query = "SELECT s from Rating s where s.user_id = :user_id"
)
})
and here I use it:
public List<Rating> getUserRatings(User user){
return em.createNamedQuery("getUserRatings", Rating.class).setParameter("user_id", user.getId()).getResultList();
}
error: Caused by: org.hibernate.HibernateException: Errors in named queries: getUserRatings
Upvotes: 1
Views: 758
Reputation: 9477
NamedQuery cannot have native query. Check if you have user_id in your entity. user_id seems like a column in DB. If so change it to java field
SELECT s from Rating s where s.userId = :user_id
Upvotes: 2