1

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.