Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 从Hibernate(MS SQLServer)生成的SQL出现问题_Sql Server_Hibernate_Orm_Jpa - Fatal编程技术网

Sql server 从Hibernate(MS SQLServer)生成的SQL出现问题

Sql server 从Hibernate(MS SQLServer)生成的SQL出现问题,sql-server,hibernate,orm,jpa,Sql Server,Hibernate,Orm,Jpa,我在Hibernate生成SQL时遇到了一个问题,该SQL不能在SQLServer上运行(在PostgreSQL上运行时没有任何问题)。我曾尝试为SQLServer设置hibernate方言,但仍然生成相同的SQL,并且仍然不起作用。HQL查询如下所示: select count(t) from ValidationLog t select count((vl.dataKey, vl.dataType)) from ValidationLog vl; 生成的SQL如下所示: selec

我在Hibernate生成SQL时遇到了一个问题,该SQL不能在SQLServer上运行(在PostgreSQL上运行时没有任何问题)。我曾尝试为SQLServer设置hibernate方言,但仍然生成相同的SQL,并且仍然不起作用。HQL查询如下所示:

 select count(t) from ValidationLog t
 select count((vl.dataKey, vl.dataType)) from ValidationLog vl;
生成的SQL如下所示:

 select count(t) from ValidationLog t
 select count((vl.dataKey, vl.dataType)) from ValidationLog vl;

所以我的问题是,它周围是否还有其他东西?希望两个数据库的代码都相同。

我觉得HQL有问题,应该是:

select count(t.dataKey) from ValidationLog t

根据JPA规范,您的JPQL查询是完全有效的:

4.8选择条款

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)
不,它是表中的一个复合键,因此必须至少有两列。您要计算多少?行数或不同的组合键数?表中的行数是我想要计算的。这应该与不同组合键的数量相同。在这种情况下,我的答案仍然有效。但SQL Server不会识别为t-SQL不具备该功能的SQL。@HLGEM什么SQL?当前生成的?如果是,那么我同意它是不正确的,这正是问题所在(根据规范,来自OP的JPQL查询是正确的,由JPA提供者生成适当的SQL)。