I have found out that when using SQLCriterion class (Expression.sql() or Restrictions.sqlRestriction()) backticks/quotes are not resolved. So it is basically on developer to provide right backticks/quotes when needed.
Code:
Expression.sql("({alias}.`start` + {alias}.`duration`) BETWEEN " + (startTime / 1000) + " AND " + (endTime / 1000))
It is ok as far as you are using one database in your application. My application needs to use two DBs - MySQL and HSQLDB; for MySQL I have to use ` and for HSQLDB I have to use ".
I am looking for a universal way how to say Hibernate to convert backticks/quotes in sql expression to the right dialect.
I have looked into the source files of SQLCriterion class and it is true that it only replaces "{alias}" string into rigt name, but that is all.
I am going to handle this by getting quote characters from curently selected dialect (Dialect.getDialect() + openQuote() and closeQuote()) and modify SQL expression everytime it is going to be used, however it would be nice if this would have been done automatically done by Hibernate.
I might be looking into wrong place, is there any way how to solve this problem? If not, please consider this as proposal for enhancement.
Thanks in advance for any comment or idea.
.md