Why is Hibernate adding schema name to Hsql functions?

青春壹個敷衍的年華 提交于 2019-12-13 19:21:30

问题


We have a legacy app which uses Hibernate 3.0.3. We do unit testing with HSQLDB. One of the queries that is generated by Hibernate looks like this:

select
 transactio0_.REASON_ID as REASON1_0_,
 transactio0_.DESCRIPTION as DESCRIPT2_93_0_,
 transactio0_.REASON_NAME as REASON3_93_0_ 
from APPS.MTL_TRANSACTION_REASONS transactio0_ 
where transactio0_.REASON_ID=54
 and transactio0_.NVL (transactio0_.disable_date, NOW() + 1 DAY) > NOW()

Note that the schema name "transactio0_" is prepended to the NVL function. Why? How can we configure Hibernate so that does not do that?

The next question deals with the version of HSQLDB that we are using. We're currently using HSQLDB 2.2.8 and would like to move up to HSQLDB 2.3.2. The above query works fine with HSQLDB 2.2.8 but fails in HSQLDB 2.3.2 with an "invalid schema name" error. Is there any way that we can configure HSQLDB 2.3.2 so that it can successfully execute the query like HSQLDB 2.2.8 does?


回答1:


The generated SQL looks strange and is certainly incorrect SQL. The transactio0_ is a table alias and shouldn't be prepended to any function name.

Perhaps the selected Hibernate dialect is not the HSQLDB dialect.

In any case, this is an old version of Hibernate and needs to be used with a version of HSQLDB that is closer to its time of release.

Regarding configuring HSQLDB to accept the malformed name, it shouldn't be possible as the original behavior was fixed because it was too lax and accepted incorrect SQL.




回答2:


I had a similiar problem. To fix this you need to put "()" together with the function name. For example:

and NVL (transactio0_.disable_date, NOW() + 1 DAY) > NOW()

change to

and NVL(transactio0_.disable_date, NOW() + 1 DAY) > NOW()

in another words, remove the space character.



来源:https://stackoverflow.com/questions/37580077/why-is-hibernate-adding-schema-name-to-hsql-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!