Problem with created SQL from Hibernate (MS SQLServer)

I have a problem with Hibernate generating SQL that doesn't work on SQLServer (works fine on PostgreSQL). I tried to install hibernation dialogs for SQLServer, but the same SQL is still generated and still does not work. The HQL query is as follows:

 select count(t) from ValidationLog t

The generated SQL looks like this:

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

So my question is, is there around? I'd love to have the same code for both databases.

+3
source share
2 answers

According to the JPA specification, your JPQL query is perfectly valid :

4.8 SELECT clause

...

The SELECT clause has the following syntax:

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_.

select count(t.someField) from ValidationLog t
+1

HQL , :

select count(t.dataKey) from ValidationLog t
0

Source: https://habr.com/ru/post/1770087/


All Articles