2016-04-28 60 views
1

我有以下查询,hibernate不支持嵌套在'从'后的问题我试图创建一个视图,但它没有工作,我想知道我怎么能使用休眠正确运行此查询我怎么可以操纵嵌套查询j2ee休眠

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; 
+1

那么你能给我们提供更多的异常信息吗? – Blank

+0

我上面创建的查询在mysql中运行良好,但问题是,当我尝试使用HQL执行时,我发现没有支持嵌套查询 我认为创建视图,但它不起作用 – Mbarki

+0

创建视图子查询? – Blank

回答

0

对于这样的查询,最简单的方法是使用本机查询。我假设你正在使用JPA/Hibernate作为ORM,所以你可以简单地这样做:

List<YourObject> resultList = yourEntityManager.createNativeQuery("nativeSQLhere", YourObject.class).getResultList(); 
+0

我没有使用原生查询,你能帮助我更多地了解它吗 – Mbarki

+0

http://www.thoughts-on-java.org/jpa-native-queries/ –