Liquibase Hibernate 插件不工作
Liquibase Hibernate Plugin Does Not Work
如此处所述 (https://github.com/liquibase/liquibase-hibernate/issues/74) 我在使 liquibase-hibernate 扩展正常工作时遇到了问题。我想我已经设置好了一切,但似乎我一直 运行 陷入奇怪的问题。我觉得我遗漏了一些简单的东西,但我想我已经按照提供的所有说明进行操作。
我正在使用 liquibase 3.3.2、Hibernate 4.3.0.Final、java 1.7.0_71 和 liquibase-hibernate4-3.5.jar。我的 CLASSPATH 环境变量是空的,但 liquibase shell 脚本向其中添加了一些内容。当我使用正常的 liquibase 命令进行交互时,我从 $LIQUIBASE_HOME/lib/ 目录中删除了没有扩展名的扩展名,它工作得很好。我重新运行了 DEBUG 输出的命令以提供更多信息。
$ echo $CLASSPATH
$ java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
$ liquibase --version
Liquibase Version: 3.3.2
$ liquibase diffChangeLog
//The below is the stuff liquibase is adding to my classpath
.:/c/repos/ServeDirtyLibsInJava/liquibaseLib/liquibase.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/liquibase-hibernate4-3.5.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/snakeyaml-1.13.jar
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateEjb3Database as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateClassicDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
DEBUG 1/19/15 10:20 AM: liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/dirtylibs
DEBUG 1/19/15 10:20 AM: liquibase: Setting auto commit to false from true
Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
SEVERE 1/19/15 10:20 AM: liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialec
t.MySQL5Dialect)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:69)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1169)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:239)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:143)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:50)
... 4 more
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:191)
... 6 more
我的 liquibase.properties 文件
driver=com.mysql.jdbc.Driver
classpath=mysql-connector-java-5.1.6.jar
url=jdbc:mysql://localhost:3306/dirtylibs
username=root
password=password
changeLogFile=changelog.xml
#referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect
referenceUsername=root
referencePassword=password
如果我取消对我的 referenceDriver 的注释,我会得到这个。我在这里缺少什么吗?我以为我拥有所有必需的依赖项,但我不确定这是否是早期扩展无法正确加载内容的问题的某种表现。
$ liquibase diffChangeLog
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateEjb3Database as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateClassicDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.snapshot.SequenceSnapshotGenerator as a Liquibase service because org.hibernate.id.factory.IdentifierGeneratorFactory is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.snapshot.TableSnapshotGenerator as a Liquibase service because org.hibernate.id.factory.IdentifierGeneratorFactory is not in the classpath
Unexpected error running Liquibase: org.hibernate.sql.Alias
SEVERE 1/19/15 10:22 AM: liquibase: org.hibernate.sql.Alias
java.lang.NoClassDefFoundError: org/hibernate/sql/Alias
at liquibase.ext.hibernate.snapshot.PrimaryKeySnapshotGenerator.<clinit>(PrimaryKeySnapshotGenerator.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at liquibase.snapshot.SnapshotGeneratorFactory.<init>(SnapshotGeneratorFactory.java:29)
at liquibase.snapshot.SnapshotGeneratorFactory.getInstance(SnapshotGeneratorFactory.java:43)
at liquibase.snapshot.SnapshotControl.addType(SnapshotControl.java:95)
at liquibase.snapshot.SnapshotControl.setTypes(SnapshotControl.java:88)
at liquibase.snapshot.SnapshotControl.<init>(SnapshotControl.java:25)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:185)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: java.lang.ClassNotFoundException: org.hibernate.sql.Alias
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
将 hibernate jar 添加到 liquibase/lib 文件夹后(这确实是错误的)错误变成了这个。我尝试恢复到旧版本的插件(同时也降级 liquibase),但没有帮助。
$ liquibase --logLevel=DEBUG diffChangeLog
.:/c/repos/ServeDirtyLibsInJava/liquibaseLib/liquibase.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/hibernate-core-4.3.0.Final.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/liquibase-hibernate4-3.5.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/snakeyaml-1.13.jar
WARNING 1/19/15 10:38 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath
DEBUG 1/19/15 10:38 AM: liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/dirtylibs
DEBUG 1/19/15 10:38 AM: liquibase: Setting auto commit to false from true
WARNING 1/19/15 10:38 AM: liquibase: Unknown database: Hibernate
DEBUG 1/19/15 10:38 AM: liquibase: Connected to null@hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect
DEBUG 1/19/15 10:38 AM: liquibase: Not adjusting the auto commit mode; it is already false
INFO 1/19/15 10:38 AM: liquibase: Error getting default schema
java.lang.NullPointerException
at liquibase.executor.jvm.JdbcExecutor$QueryCallableStatementCallback.doInCallableStatement(JdbcExecutor.java:383)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:96)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:132)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:143)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:166)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:161)
at liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:318)
at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:301)
at liquibase.CatalogAndSchema.customize(CatalogAndSchema.java:132)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:116)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:190)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
DEBUG 1/19/15 10:38 AM: liquibase: Computed checksum for 1421681927678 as b60efdd1567f2fd4e5407a8d157cb0b6
Unexpected error running Liquibase: java.lang.NullPointerException
SEVERE 1/19/15 10:38 AM: liquibase: java.lang.NullPointerException
liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.NullPointerException
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:123)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerException
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
... 3 more
Caused by: java.lang.NullPointerException
at liquibase.snapshot.jvm.CatalogSnapshotGenerator.getDatabaseCatalogNames(CatalogSnapshotGenerator.java:82)
at liquibase.snapshot.jvm.CatalogSnapshotGenerator.snapshotObject(CatalogSnapshotGenerator.java:41)
at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:60)
at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:163)
at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:55)
at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:37)
at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:25)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:126)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:119)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:190)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
... 4 more
我通过将这些 jar 添加到我的类路径来让它工作。这非常令人困惑,而且没有很好的记录。
我经历的过程是:
在此处 (https://github.com/liquibase/liquibase-hibernate/releases) 下载正确插件项目的源代码,在我的例子中是 liquibase-hibernate4-3.5。
运行mvn dependency:copy-dependencies
。这会将它们转储到 /target/dependency/
。复制所有这些 jar 并将它们放入您的 LIQUIBASE_HOME/lib
目录。
我正在使用 gradle 所以我使用自定义任务来复制我所有的依赖项。如果您使用的是 Maven,则可以在您自己的项目中使用 2 中的相同步骤来获取所有依赖项。我将这些库从我的输出目录复制到 LIQUIBASE_HOME/lib
目录中。
task copyToLib(type: Copy) {
into "$buildDir/output/libs"
from configurations.runtime
}
我也把正确的hibernate-liquibase-4.3.5.jar
放到了LIQUIBASE_HOME/lib
目录下
这给了我插件所需的所有依赖项。
这是一团乱七八糟的大麻烦,但你能做什么:(
我尝试的路径与接受的答案有点不同。我在 war 的 pom.xml(我使用的是 maven)中创建了一个开发配置文件,它与默认配置文件完全相同,但包括 war/WEB-INF/lib 下的 Liquibase-hibernate 依赖 jar 文件.然后我没有使用提供的 liquibase 命令行,而是直接使用 liquibase.jar 文件,类路径是我的 war 文件:
java -jar $LIQUIBASE/liquibase.jar --classpath=<WAR FILE HERE> --defaultsFile=<yourpath>/liquibase.properties --logLevel=info
然后创建了一个方便的脚本,它将使用该 liquibase-hibernate 配置文件构建我的项目,然后执行 diffChangeLog 命令。
如果您检查此插件的源代码,以下依赖项(所有 spring 依赖项)在 pom 中被标记为 "provided" 范围:
spring-test
spring-jdbc
spring-beans
spring-context
spring-orm
因此插件会假定这些已由您的应用程序在类路径中提供,但这不会自动发生在您的 Maven 构建中,因为它不会 运行 与您的应用程序具有相同的类路径.
所以,要修复,在你的插件中添加依赖项,比做 jar 文件随机播放更容易:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
</dependencies>
</plugin>
如果您愿意,可以在 github 存储库上执行拉取请求以从 pom 中删除提供的范围,哦,可能还有这一行:
<role>architect</role>
我遇到了同样的错误。我通过删除 hibernate.cfg.xml 中的 hbm2ddl-属性 来修复它。如果此 属性 打开,则无法在 cfg.xml 中读取驱动程序 class。在 git 的 liquibase-hibernate wiki 中有一个部分说 "Why not to use HBM2DDL" 但它并没有真正说要从 cfg.xml 中删除它。
如此处所述 (https://github.com/liquibase/liquibase-hibernate/issues/74) 我在使 liquibase-hibernate 扩展正常工作时遇到了问题。我想我已经设置好了一切,但似乎我一直 运行 陷入奇怪的问题。我觉得我遗漏了一些简单的东西,但我想我已经按照提供的所有说明进行操作。
我正在使用 liquibase 3.3.2、Hibernate 4.3.0.Final、java 1.7.0_71 和 liquibase-hibernate4-3.5.jar。我的 CLASSPATH 环境变量是空的,但 liquibase shell 脚本向其中添加了一些内容。当我使用正常的 liquibase 命令进行交互时,我从 $LIQUIBASE_HOME/lib/ 目录中删除了没有扩展名的扩展名,它工作得很好。我重新运行了 DEBUG 输出的命令以提供更多信息。
$ echo $CLASSPATH
$ java -version
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
$ liquibase --version
Liquibase Version: 3.3.2
$ liquibase diffChangeLog
//The below is the stuff liquibase is adding to my classpath
.:/c/repos/ServeDirtyLibsInJava/liquibaseLib/liquibase.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/liquibase-hibernate4-3.5.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/snakeyaml-1.13.jar
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateEjb3Database as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:42 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateClassicDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
DEBUG 1/19/15 10:20 AM: liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/dirtylibs
DEBUG 1/19/15 10:20 AM: liquibase: Setting auto commit to false from true
Unexpected error running Liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
SEVERE 1/19/15 10:20 AM: liquibase: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialec
t.MySQL5Dialect)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:69)
at liquibase.integration.commandline.Main.createReferenceDatabaseFromCommandParams(Main.java:1169)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:239)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:143)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:50)
... 4 more
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url (hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect)
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:191)
... 6 more
我的 liquibase.properties 文件
driver=com.mysql.jdbc.Driver
classpath=mysql-connector-java-5.1.6.jar
url=jdbc:mysql://localhost:3306/dirtylibs
username=root
password=password
changeLogFile=changelog.xml
#referenceDriver=liquibase.ext.hibernate.database.connection.HibernateDriver
referenceUrl=hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect
referenceUsername=root
referencePassword=password
如果我取消对我的 referenceDriver 的注释,我会得到这个。我在这里缺少什么吗?我以为我拥有所有必需的依赖项,但我不确定这是否是早期扩展无法正确加载内容的问题的某种表现。
$ liquibase diffChangeLog
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateEjb3Database as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateClassicDatabase as a Liquibase service because org.hibernate.dialect.Dialect is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.snapshot.SequenceSnapshotGenerator as a Liquibase service because org.hibernate.id.factory.IdentifierGeneratorFactory is not in the classpath
WARNING 1/19/15 12:49 AM: liquibase: Can not use class liquibase.ext.hibernate.snapshot.TableSnapshotGenerator as a Liquibase service because org.hibernate.id.factory.IdentifierGeneratorFactory is not in the classpath
Unexpected error running Liquibase: org.hibernate.sql.Alias
SEVERE 1/19/15 10:22 AM: liquibase: org.hibernate.sql.Alias
java.lang.NoClassDefFoundError: org/hibernate/sql/Alias
at liquibase.ext.hibernate.snapshot.PrimaryKeySnapshotGenerator.<clinit>(PrimaryKeySnapshotGenerator.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at liquibase.snapshot.SnapshotGeneratorFactory.<init>(SnapshotGeneratorFactory.java:29)
at liquibase.snapshot.SnapshotGeneratorFactory.getInstance(SnapshotGeneratorFactory.java:43)
at liquibase.snapshot.SnapshotControl.addType(SnapshotControl.java:95)
at liquibase.snapshot.SnapshotControl.setTypes(SnapshotControl.java:88)
at liquibase.snapshot.SnapshotControl.<init>(SnapshotControl.java:25)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:185)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: java.lang.ClassNotFoundException: org.hibernate.sql.Alias
at java.net.URLClassLoader.run(URLClassLoader.java:366)
at java.net.URLClassLoader.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 18 more
将 hibernate jar 添加到 liquibase/lib 文件夹后(这确实是错误的)错误变成了这个。我尝试恢复到旧版本的插件(同时也降级 liquibase),但没有帮助。
$ liquibase --logLevel=DEBUG diffChangeLog
.:/c/repos/ServeDirtyLibsInJava/liquibaseLib/liquibase.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/hibernate-core-4.3.0.Final.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/liquibase-hibernate4-3.5.jar:/c/repos/ServeDirtyLibsInJava/liquibaseLib/lib/snakeyaml-1.13.jar
WARNING 1/19/15 10:38 AM: liquibase: Can not use class liquibase.ext.hibernate.database.HibernateSpringDatabase as a Liquibase service because org.springframework.beans.factory.support.BeanDefinitionRegistry is not in the classpath
DEBUG 1/19/15 10:38 AM: liquibase: Connected to root@localhost@jdbc:mysql://localhost:3306/dirtylibs
DEBUG 1/19/15 10:38 AM: liquibase: Setting auto commit to false from true
WARNING 1/19/15 10:38 AM: liquibase: Unknown database: Hibernate
DEBUG 1/19/15 10:38 AM: liquibase: Connected to null@hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect=org.hibernate.dialect.MySQL5Dialect
DEBUG 1/19/15 10:38 AM: liquibase: Not adjusting the auto commit mode; it is already false
INFO 1/19/15 10:38 AM: liquibase: Error getting default schema
java.lang.NullPointerException
at liquibase.executor.jvm.JdbcExecutor$QueryCallableStatementCallback.doInCallableStatement(JdbcExecutor.java:383)
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:96)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:132)
at liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:143)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:166)
at liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:161)
at liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java:318)
at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:301)
at liquibase.CatalogAndSchema.customize(CatalogAndSchema.java:132)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:116)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:190)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
DEBUG 1/19/15 10:38 AM: liquibase: Computed checksum for 1421681927678 as b60efdd1567f2fd4e5407a8d157cb0b6
Unexpected error running Liquibase: java.lang.NullPointerException
SEVERE 1/19/15 10:38 AM: liquibase: java.lang.NullPointerException
liquibase.exception.LiquibaseException: liquibase.command.CommandExecutionException: java.lang.NullPointerException
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:123)
at liquibase.integration.commandline.Main.doMigration(Main.java:936)
at liquibase.integration.commandline.Main.run(Main.java:175)
at liquibase.integration.commandline.Main.main(Main.java:94)
Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerException
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)
at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
... 3 more
Caused by: java.lang.NullPointerException
at liquibase.snapshot.jvm.CatalogSnapshotGenerator.getDatabaseCatalogNames(CatalogSnapshotGenerator.java:82)
at liquibase.snapshot.jvm.CatalogSnapshotGenerator.snapshotObject(CatalogSnapshotGenerator.java:41)
at liquibase.snapshot.jvm.JdbcSnapshotGenerator.snapshot(JdbcSnapshotGenerator.java:60)
at liquibase.snapshot.SnapshotGeneratorChain.snapshot(SnapshotGeneratorChain.java:50)
at liquibase.snapshot.DatabaseSnapshot.include(DatabaseSnapshot.java:163)
at liquibase.snapshot.DatabaseSnapshot.init(DatabaseSnapshot.java:55)
at liquibase.snapshot.DatabaseSnapshot.<init>(DatabaseSnapshot.java:37)
at liquibase.snapshot.JdbcDatabaseSnapshot.<init>(JdbcDatabaseSnapshot.java:25)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:126)
at liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:119)
at liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:190)
at liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.java:51)
at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
... 4 more
我通过将这些 jar 添加到我的类路径来让它工作。这非常令人困惑,而且没有很好的记录。 我经历的过程是:
在此处 (https://github.com/liquibase/liquibase-hibernate/releases) 下载正确插件项目的源代码,在我的例子中是 liquibase-hibernate4-3.5。
运行
mvn dependency:copy-dependencies
。这会将它们转储到/target/dependency/
。复制所有这些 jar 并将它们放入您的LIQUIBASE_HOME/lib
目录。我正在使用 gradle 所以我使用自定义任务来复制我所有的依赖项。如果您使用的是 Maven,则可以在您自己的项目中使用 2 中的相同步骤来获取所有依赖项。我将这些库从我的输出目录复制到
LIQUIBASE_HOME/lib
目录中。task copyToLib(type: Copy) { into "$buildDir/output/libs" from configurations.runtime }
我也把正确的
hibernate-liquibase-4.3.5.jar
放到了LIQUIBASE_HOME/lib
目录下
这给了我插件所需的所有依赖项。
这是一团乱七八糟的大麻烦,但你能做什么:(
我尝试的路径与接受的答案有点不同。我在 war 的 pom.xml(我使用的是 maven)中创建了一个开发配置文件,它与默认配置文件完全相同,但包括 war/WEB-INF/lib 下的 Liquibase-hibernate 依赖 jar 文件.然后我没有使用提供的 liquibase 命令行,而是直接使用 liquibase.jar 文件,类路径是我的 war 文件:
java -jar $LIQUIBASE/liquibase.jar --classpath=<WAR FILE HERE> --defaultsFile=<yourpath>/liquibase.properties --logLevel=info
然后创建了一个方便的脚本,它将使用该 liquibase-hibernate 配置文件构建我的项目,然后执行 diffChangeLog 命令。
如果您检查此插件的源代码,以下依赖项(所有 spring 依赖项)在 pom 中被标记为 "provided" 范围:
spring-test
spring-jdbc
spring-beans
spring-context
spring-orm
因此插件会假定这些已由您的应用程序在类路径中提供,但这不会自动发生在您的 Maven 构建中,因为它不会 运行 与您的应用程序具有相同的类路径.
所以,要修复,在你的插件中添加依赖项,比做 jar 文件随机播放更容易:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.1</version>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>3.5.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.2.RELEASE</version>
</dependency>
</dependencies>
</plugin>
如果您愿意,可以在 github 存储库上执行拉取请求以从 pom 中删除提供的范围,哦,可能还有这一行:
<role>architect</role>
我遇到了同样的错误。我通过删除 hibernate.cfg.xml 中的 hbm2ddl-属性 来修复它。如果此 属性 打开,则无法在 cfg.xml 中读取驱动程序 class。在 git 的 liquibase-hibernate wiki 中有一个部分说 "Why not to use HBM2DDL" 但它并没有真正说要从 cfg.xml 中删除它。