我从生产代码中使用Oracle SUBSTR()
方法命名查询。如何使这些呼叫与H2 SUBSTRING()
一起使用?
我正在尝试使用H2进行测试。我创建了hibernate.cfg.xml
的副本并进行了更改,以使其连接到H2数据库。 hibernate.cfg.xml
引用了一些*.hbm.xml
文件,其中一些包含使用Oracle SUBSTR()
的命名查询。
我已经看过CREATE ALIAS
(http://h2database.com/html/commands.html#create_alias)上的文档,但是想不出如何使它足够早地工作,因此新的命令甚至在Hibernate初始化期间可用。 / p>
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jun 24, 2019 4:01:01 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.0.9.Final}
Jun 24, 2019 4:01:01 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.bytecode.use_reflection_optimizer=false}
Jun 24, 2019 4:01:01 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 24, 2019 4:01:02 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
Jun 24, 2019 4:01:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Jun 24, 2019 4:01:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.h2.Driver] at URL [jdbc:h2:mem:test;MODE=Oracle]
Jun 24, 2019 4:01:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=sa, password=****}
Jun 24, 2019 4:01:03 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
Jun 24, 2019 4:01:03 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jun 24, 2019 4:01:03 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
Jun 24, 2019 4:01:05 PM org.hibernate.internal.SessionFactoryImpl <init>
ERROR: HHH000177: Error in named query: findKindIdXXXXXXXXX
org.hibernate.QueryException: undefined alias: SUBSTR [SELECT
xxx.yyyyy, SUBSTR(nmvz.eigKennzeichen, 2, 1)
FROM
[...]
WHERE
[...]
如何在休眠初始化中尽早定义别名,以使此错误消息消失?