我遇到Hibernate生成SQL不能在SQLServer上运行的问题(适用于PostgreSQL而没有任何问题)。我试图为SQLServer设置hibernate方言,但仍然生成相同的SQL但仍然无法正常工作。 HQL查询如下所示:
select count(t) from ValidationLog t
生成的SQL如下所示:
select count((vl.dataKey, vl.dataType)) from ValidationLog vl;
所以我的问题是,无论如何它周围?真的希望两个数据库都有相同的代码。
答案 0 :(得分:1)
根据JPA规范,您的JPQL查询完全有效:
4.8 SELECT子句
...
SELECT子句具有以下内容 语法:
select_clause ::= SELECT [DISTINCT] select_expression {, select_expression}* select_expression ::= single_valued_path_expression | aggregate_expression | identification_variable | OBJECT(identification_variable) | constructor_expression constructor_expression ::= NEW constructor_name ( constructor_item {, constructor_item}*) constructor_item ::= single_valued_path_expression | aggregate_expression aggregate_expression ::= { AVG | MAX | MIN | SUM } ([DISTINCT] state_field_path_expression) | COUNT ([DISTINCT] identification_variable | state_field_path_expression | single_valued_association_path_expression)
但是,您可能是HHH-4044,HHH-3096,HHH-2266(甚至HHH-5419)等问题中报告的错误的受害者。
可能的解决方法:使用 state_field_path_expression 。
select count(t.someField) from ValidationLog t
答案 1 :(得分:0)
HQL对我来说错了,应该是:
select count(t.dataKey) from ValidationLog t