Note that there are some explanatory texts on larger screens.

plurals
  1. POjpa and native queries
    primarykey
    data
    text
    <p>I faced with a strange thing with native queries:</p> <p>If I'm trying to use named native query like the following</p> <pre><code>@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)") </code></pre> <p>The application cannot run and I have </p> <pre><code>org.hibernate.HibernateException: Errors in named queries: native_count_avg_guest_quizzes_ </code></pre> <p>But the same query works fine if I do not use NamedNativeQuery and merely create a dynamic native query like the following:</p> <pre><code>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() </code></pre> <p>Why? What I'm doing wrong with NamedNativeQuery? Thanks</p> <p><strong>Update:</strong> Entity class is as following</p> <pre><code>@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 { ....... } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload