ネイティブクエリで奇妙なことに直面しました:
次のような名前付きネイティブ クエリを使用しようとしている場合
@NamedNativeQuery(name = "native_count_avg_guest_quizzes", resultClass = java.math.BigDecimal.class, query = "select avg(c) as r from ((select count(*) as c from user_quiz uq join user u on (uq.user_id = u.id) where u.status = 'temporary' group by u.id) as res)")
アプリケーションを実行できません。
org.hibernate.HibernateException: Errors in named queries: native_count_avg_guest_quizzes_
ただし、NamedNativeQuery を使用せず、次のような動的なネイティブ クエリを作成するだけであれば、同じクエリで問題なく動作します。
entityManager.createNativeQuery(
"select avg(c) as r from ((select count(*) as c from user_quiz uq join user u on (uq.user_id = u.id) where u.status = 'temporary' group by u.id) as res)")
.getSingleResult()
なんで?NamedNativeQuery で何が間違っていますか? ありがとう
更新: エンティティクラスは次のとおりです
@Entity
@Table(name = "user_quiz")
@NamedNativeQueries({
@NamedNativeQuery(name = "native_count_avg_guest_quizzes", resultClass = java.math.BigDecimal.class, query = "select avg(c) as r from ((select count(*) as c from user_quiz uq join user u on (uq.user_id = u.id) where u.status = 'temporary' group by u.id) as res)")
})
@NamedQueries({
@NamedQuery(name = "list_clients_quizzes", query = "select uq from UserQuiz uq where uq.quiz.client.id = :clientId"),
.......
})
public class UserQuiz extends Measurable {
.......
}