Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA errors, using HAVING count with Hibernate

 
Nelson Gomes
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help me , I need to use having clause in Hibernate

Sorry how do use having clause in hibernate ?
Seems that it´s not recognizing having clause

Look at my code


String queryDB = "select med.normalizedNif from MvEntityDepuration med WHERE";

if(nif){

   queryDB += " med.normalizedNif HAVING count(*)>1 group by med.normalizedNif ";
}

LOGGER.debugv("Nelson: Query a Rodar: {0}", queryDB);

List<Object[]> dataInDb =  em.createQuery(queryDB, Object[].class).getResultList();


error: Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: having near line 1, column 101 [select med.normalizedNif from pt.infarmed.gent.model.MvEntityDepuration med WHERE med.normalizedNif having count(*)>1 group by med.normalizedNif ]




 
Campbell Ritchie
Sheriff
Posts: 51388
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As on all websites, please don't use ALL UPPER CASE writing. I shall change it for you just this once. I shall also move you to the Hibernate forum; you appear to have arrived in the wrong place.
 
Rob Spoor
Sheriff
Pie
Posts: 20751
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just like in SQL, HAVING should come after GROUP BY. I'm also not sure if the WHERE clause is valid; med.normalizedNif doesn't look like a valid JPQL boolean expression.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic