Mysql查询工作正常,但Hibernate不接受它

时间:2012-01-31 10:06:17

标签: mysql hibernate hql

我有两张桌子:

enter image description here

我在MySQL中运行查询工作正常:

SELECT sum(toplam) 
FROM 
      (SELECT ut.uye, t.fiyatTuru AS FT, ut.nominalDeger * t.birimFiyati AS toplam         
       FROM UyeTeminat AS ut JOIN Teminat AS t ON ut.teminat = t.teminatId 
       WHERE ut.uye= :uyeId and t.fiyatTuru = :fiyatTuru
      ) AS t1 
GROUP BY t1.FT

上述查询的结果是:

sum(TOPLAM)
2010.000000
5550780.000000

然而,当我将其转换为HQL时:

BigDecimal toplamTLTeminatiInteger;
toplamTLTeminatiInteger = (BigDecimal) session.createSQLQuery("SELECT sum(toplam) FROM (SELECT ut.uye, t.fiyatTuru AS FT, ut.nominalDeger * t.birimFiyati AS toplam FROM UyeTeminat AS ut JOIN Teminat AS t ON ut.teminat = t.teminatId WHERE ut.uye= :uyeId and t.fiyatTuru = :fiyatTuru) AS t1 GROUP BY t1.FT")
                    .setParameter("uyeId", uyeTeminat.getUye() )
                    .setParameter("fiyatTuru", uyeTeminat.getTeminat().getFiyatTuru()).uniqueResult();

我收到了这个错误:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'database.uyeteminat' doesn't exist

表的名称没有错,我在其他查询中使用UyeTeminat。

我在HQL中不允许在MySql中做什么?

0 个答案:

没有答案