1

I have the following query, the problem that hibernate does not support nested after the 'from' I tried to create a view, but it did not work, I want to know how can I use hibernate to run this query correctly

SELECT sum(dc.nbrDefaut) def, a.nb control,c.id_of
FROM controlequalite c ,detailscontrole dc,
(select sum(nbreControlle) nb, id_monitrice 
  from controlequalite group by id_monitrice) a
  where c.id = dc.id_controle 
and c.id_monitrice = a.id_monitrice 
and  c.date >= '2016-03-25 00:00:00' 
group by c.id_monitrice,c.id_of;
v.ladynev
  • 19,275
  • 8
  • 46
  • 67
Mbarki
  • 11
  • 2
  • 1
    So could you give us more exception information? – Blank Apr 28 '16 at 10:09
  • the query that I created above works well in mysql but the problem is that when I tried to execute with HQL I found that did not supporet the nested query I thought to create a view, but it does not work – Mbarki Apr 28 '16 at 10:17
  • Create a view of subquery? – Blank Apr 28 '16 at 10:19
  • yes create a view with subquery – Mbarki Apr 28 '16 at 10:25
  • Take a look of this [JPA/hibernate subquery in from clause](http://stackoverflow.com/questions/7269010/jpa-hibernate-subquery-in-from-clause) which said HQL do not support feature you want. – Blank Apr 29 '16 at 01:22

1 Answers1

0

With a query like this, the simplest way is to use a native query. I'm assuming you are using JPA/Hibernate as ORM, so you can simply do like:

List<YourObject> resultList = yourEntityManager.createNativeQuery("nativeSQLhere", YourObject.class).getResultList();
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51