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

有帮助吗?

解决方案

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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top