我正在研究DROPWIZARD MIGRATION应用程序[Dropwizard 0.7.0]。要使用migration.xml生成db结构,我正在为Postgres和ORACLE数据库运行db migrate命令。对于Postgres,我成功地能够生成数据库结构,但是当尝试ORACLE时,以下细节会出现异常
database:
# the name of your JDBC driver
# driverClass: org.postgresql.Driver
driverClass: oracle.jdbc.driver.OracleDriver
# the username
user: system
# user: postgres
# the password
password: Passw0rd
# the JDBC URL
# url: "jdbc:postgresql://192.168.1.130:5432/mydb"
url: "jdbc:oracle:thin:@192.168.1.130:1521/mydb"
# Hibernate dialect
# dialect: "org.hibernate.dialect.PostgreSQLDialect"
dialect: "org.hibernate.dialect.Oracle10gDialect"
# hibernate.connection.provider_class
connectionProviderClass: org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
对于这些oracle设置我得到了异常
ERROR [2016-03-07 07:59:24,001] org.apache.tomcat.jdbc.pool.ConnectionPool: Unable to create initial connections of pool.
Exception in thread "main" java.lang.reflect.InvocationTargetException
! java.sql.SQLException: Validation Query Failed, enable logValidationErrors for more details.
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
! at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:715) [tomcat-jdbc-7.0.50.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
! at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635) [tomcat-jdbc-7.0.50.jar:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
! at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486) [tomcat-jdbc-7.0.50.jar:na]
at java.lang.reflect.Method.invoke(Method.java:606)
! at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144) [tomcat-jdbc-7.0.50.jar:na]
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121)
! at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116) [tomcat-jdbc-7.0.50.jar:na]
Caused by: java.sql.SQLException: Validation Query Failed, enable logValidationErrors for more details.
! at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103) [tomcat-jdbc-7.0.50.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:715)
! at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127) [tomcat-jdbc-7.0.50.jar:na]
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
! at io.dropwizard.migrations.CloseableLiquibase.<init>(CloseableLiquibase.java:17) [dropwizard-migrations-0.7.0.jar:0.7.0]
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
! at io.dropwizard.migrations.AbstractLiquibaseCommand.openLiquibase(AbstractLiquibaseCommand.java:66) [dropwizard-migrations-0.7.0.jar:0.7.0]
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
! at io.dropwizard.migrations.AbstractLiquibaseCommand.run(AbstractLiquibaseCommand.java:53) [dropwizard-migrations-0.7.0.jar:0.7.0]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
! at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) [dropwizard-core-0.7.0.jar:0.7.0]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
! at io.dropwizard.cli.Cli.run(Cli.java:70) [dropwizard-core-0.7.0.jar:0.7.0]
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
! at io.dropwizard.Application.run(Application.java:72) [dropwizard-core-0.7.0.jar:0.7.0]
at io.dropwizard.migrations.CloseableLiquibase.<init>(CloseableLiquibase.java:17)
! at org.opensample.MyApplication.main(MyApplication.java:59) [classes/:na]
at io.dropwizard.migrations.AbstractLiquibaseCommand.openLiquibase(AbstractLiquibaseCommand.java:66)
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_45]
at io.dropwizard.migrations.AbstractLiquibaseCommand.run(AbstractLiquibaseCommand.java:53)
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_45]
at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_45]
at io.dropwizard.cli.Cli.run(Cli.java:70)
! at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_45]
at io.dropwizard.Application.run(Application.java:72)
! at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:121) [idea_rt.jar:na]
at org.opensample.Mypplication.main(MyApplication.java:59)
... 5 more
答案 0 :(得分:0)
原因是DropWizard使用的默认验证定义为
SELECT 1;
,DB2不支持。一种可能的解决方案是在DropWizard配置中设置validationQuery参数。 DB2的推荐配置值是:
validationQuery: select 1 from sysibm.sysdummy1
您可以找到其他数据库引擎here的不同定义的详细答案。