0

The following shows debug from my Quarkus app. The translated SQL is not equivalent to the HQL Query.... The logic from the BOLD section Depending on how SQL parses the and/or logic, the two are not equivalent. The following output is from my log showing the resulting HQL and SQL.... My original code is just a query string in the ORM ::find() method...

2022-09-12 14:17:36,027 DEBUG [org.hib.hql.int.ast.QueryTranslatorImpl] (vert.x-eventloop-thread-1) HQL: from com.xxxxx.geo.GeoName where geo_country_code = :cc and geo_admin1_code = :admin1 and ((geo_feature_class = :class0 and geo_feature_code = :code0) or (geo_feature_class = :class1 and geo_feature_code = :code1) or (geo_feature_class = :class2 and geo_feature_code = :code2)) order by name 2022-09-12 14:17:36,027 DEBUG

[org.hib.hql.int.ast.QueryTranslatorImpl] (vert.x-eventloop-thread-1) SQL: select geoname0_.geo_id as geo_id1_3_, geoname0_.geo_admin1_code as geo_admi2_3_, geoname0_.geo_admin2_code as geo_admi3_3_, geoname0_.geo_admin3_code as geo_admi4_3_, geoname0_.geo_admin4_code as geo_admi5_3_, geoname0_.geo_admin5_code as geo_admi6_3_, geoname0_.geo_alt_country_codes as geo_alt_7_3_, geoname0_.geo_alt_names as geo_alt_8_3_, geoname0_.geo_country_code as geo_coun9_3_, geoname0_.geo_dem as geo_dem10_3_, geoname0_.geo_elevation as geo_ele11_3_, geoname0_.geo_feature_class as geo_fea12_3_, geoname0_.geo_feature_code as geo_fea13_3_, geoname0_.geo_last_modified as geo_las14_3_, geoname0_.geo_latitude as geo_lat15_3_, geoname0_.geo_longitude as geo_lon16_3_, geoname0_.geo_name as geo_nam17_3_, geoname0_.geo_name_ascii as geo_nam18_3_, geoname0_.geo_population as geo_pop19_3_, geoname0_.geo_timezone as geo_tim20_3_ from geo.GeoNames geoname0_ where geo_country_code=? and geo_admin1_code=? and (geo_feature_class=? and geo_feature_code=? or geo_feature_class=? and geo_feature_code=? or geo_feature_class=? and geo_feature_code=?) order by geoname0_.geo_name

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30
R Soph
  • 11
  • 2
  • You will need to provide some more information like the HQL query and the expected SQL query. It would be also good to have the hibernate entities. – Stephan Strate Sep 11 '22 at 07:44
  • I updated the original example to provide a better example.... I think it comes down to how SQL parses the and/or but I am searching for 3 distinct class.feature combinations... it is not intuitive as to how the bold text above would get processed – R Soph Sep 12 '22 at 18:31
  • 1
    Just to make sure. `and` has precedence over `or`. That means you can leave away the brackets around the and conditions. That also means the HQL and SQL are the same, as far as I can see it. – Stephan Strate Sep 14 '22 at 18:14

0 Answers0