Liquibase Hibernate插件不起作用 [英] Liquibase Hibernate Plugin Does Not Work

查看:550
本文介绍了Liquibase Hibernate插件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如此处所述( https://github.com/liquibase/liquibase-hibernate/问题/ 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 /目录中删除扩展名,但没有扩展名,它工作得很好。

  $ echo $ CLASSPATH 

我在DEBUG输出中重新输入命令以提供更多信息。
$ java -version
java版本1.7.0_71
Java™SE运行时环境(build 1.7.0_71-b14)
Java HotSpot™64位Server VM(构建24.71-b01,混合模式)

$ liquibase --version
Liquibase版本:3.3.2

$ liquibase diffChangeLog
/ /下面是liquibase添加到我的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:不能使用liquibase.ext.hibernate.database.HibernateEjb3Database类作为Liquibase服务因为org.hibernate.dialect.Dialect不在类路径中
警告2015年1月19日12:42:liquibase:无法使用类liquibase.ext.hibernate.database.HibernateSpringDatabase a sa Liquibase服务,因为org.hibernate.dialect.Dialect不在类路径中
WARNING 1/19/15 12:42 AM:liquibase:无法将类liquibase.ext.hibernate.database.HibernateClassicDatabase用作Liquibase服务因为org.hibernate.dialect.Dialect不在类路径中
DEBUG 1/19/15 10:20 AM:liquibase:连接到root @ localhost @ jdbc:mysql:// localhost:3306 / dirtylibs
DEBUG 1/19/15 10:20 AM:liquibase:将自动提交设置为false从真实
运行Liquibase:java.lang.RuntimeException的意外错误:无法找到数据库驱动程序:未指定驱动程序类,无法(hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect = org.hibernate.dialect.MySQL5Dialect)

SEVERE 1/19/15 10:20 AM:liquibase: java.lang.RuntimeException:无法找到数据库驱动程序:Driver类未指定,无法从url中确定(hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect = org.hibernate.dialect.MySQL5Dialect)
liquibase.exception.DatabaseException:liquibase.exception.DatabaseException:java.lang.RuntimeException:找不到数据库驱动程序:未指定驱动程序类,无法从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)
在liquibase.integration.commandline.Main.main(Main.java:94)
导致:liquibase.exception.DatabaseException:java.lang .RuntimeException:找不到数据库驱动程序:未指定驱动程序类,无法从th中确定e网址(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
导致通过:java.lang.RuntimeException:无法找到数据库驱动程序:Driver类未指定,无法确定从该网址(hibernate:春: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:// localh ost:3306 / dirtylibs
username = root
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 $ b $ referencePassword = password

如果我取消注释我的referenceDriver,我可以得到它。有什么我在这里失踪?我认为我有所有必需的依赖关系,我不确定这是否是早期问题的扩展无法正确加载内容的一些表现形式。

  $ liquibase diffChangeLog 
WARNING 1/19/15 12:49 AM:liquibase:由于org.hibernate.dialect不能使用liquibase.ext.hibernate.database.HibernateEjb3Database类作为Liquibase服务.Dialect不在类路径中
WARNING 1/19/15 12:49 AM:liquibase:因为org.hibernate.dialect.Dialect不能使用class liquibase.ext.hibernate.database.HibernateSpringDatabase作为Liquibase服务不在classpath中
警告2015年1月19日12:49:liquibase:不能使用class liquibase.ext.hibernate.database.HibernateClassicDatabase作为Liquibase服务,因为org.hibernate.dialect.Dialect不在classpath
WARNING 1/19/15 12:49 AM:liquibase:无法使用class liquibase.ext.hibernate.snapshot.SequenceSnapshotGenerator作为Liquibase服务,因为org.hibernate.id.facto ry.IdentifierGeneratorFactory不在类路径中
WARNING 1/19/15 12:49 AM:liquibase:由于org.hibernate.id.factory不能使用类liquibase.ext.hibernate.snapshot.TableSnapshotGenerator作为Liquibase服务.IdentifierGeneratorFactory不在类路径中
运行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(本机方法)
在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
是java .lang.reflect.Constructor.newInstance(Constructor.java:526)
在liquibase.snapshot.SnapshotGeneratorFactory<初始化>(SnapshotGeneratorFactory.java:29)
。在liquibase.snapshot.SnapshotGeneratorFactory.getInstance(SnapshotGeneratorFactory.java:43)
。在liquibase.snapshot.SnapshotControl.addType( (SnapshotControl.java:95)
at liquibase.snapshot.SnapshotControl.setTypes(SnapshotControl.java:88)
at liquibase.snapshot.SnapshotControl。< init>(SnapshotControl.java:25)
在liquibase.command.DiffCommand.createReferenceSnapshot(DiffCommand.java:185)
在liquibase.command.DiffCommand.createDiffResult(DiffCommand.java:140)
在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)
在liquibase.integration.commandline.Main.run(Main.java:175)
在liquibase.integration.commandline.Main.main(Main.java:94)
导致通过:java.lang.ClassNotFoundException:org.hibernate.sql.Alias $ b $在java.net.URLClassLoader $ 1.run(URLClassLoader.java:366)$ b $在java.net.URLClassLoader $ 1.run(URLClassLoader .java:355)在java.security.AccessController.doPrivileged处使用
(本地方法)在java.net.URLClassLoader.findClass处使用
(URLClassLoader.java:354)在java.lang.ClassLoader处使用
.loadClass(ClassLoader.java:425)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:308)$ b $ java.util.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:由于org.springframework.beans.factory.support.BeanDefinitionRegistry不在类路径中,因此不能使用class liquibase.ext.hibernate.database.HibernateSpringDatabase作为Liquibase服务
DEBUG 1/19/15 10:38 AM:liquibase :连接到root @ localhost @ jdbc:mysql:// localhost:3306 / dirtylibs
DEBUG 1/19/15 10:38 AM:liquibase:将自动提交设置为false从true
WARNING 1/19 / 15 10:38 AM:liquibase:未知数据库:Hibernate
DEBUG 1/19/15 10:38 AM:liquibase:Co nnected to null @ hibernate:spring:com.companyname.dirtylibs.persistence.entities?dialect = org.hibernate.dialect.MySQL5Dialect
DEBUG 1/19/15 10:38 AM:liquibase:不调整自动提交模式;它已经是假的
INFO 1/19/15 10:38 AM:liquibase:获取默认模式时出错
在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)
在liquibase.executor.jvm.JdbcExecutor.query(JdbcExecutor.java:143)
在liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:151)
在liquibase.executor。 jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:166)
在liquibase.executor.jvm.JdbcExecutor.queryForObject(JdbcExecutor.java:161)
在liquibase.database.AbstractJdbcDatabase.getConnectionSchemaName(AbstractJdbcDatabase.java: 318)
at liquibase.database.AbstractJdbcDatabase.getDefaultSchemaName(AbstractJdbcDatabase.java:301)
at liquibase.CatalogAndSchema.customize(CatalogAndSchema.java:132)
在liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:116)
在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:1421681927678的计算校验和为b60efdd1567f2fd4e5407a8d157cb0b6
意外的错误或运行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)
在liquibase.integration.commandline.Main.run(Main.java:175)
在liquibase.integration.commandline.Main.main(Main.java:94)
导致:liquibase.command .CommandExecutionException:在liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)显示java.lang.NullPointerException

在liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(CommandLineUtils.java:121)
... 3 more
导致:java.lang.NullPointerException
at liquibase.snapshot.jvm.CatalogSn apshotGenerator.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:37)
at liquibase.snapshot.JdbcDatabaseSnapshot。< init>(JdbcDatabaseSnapshot.java).init(DatabaseSnapshot.java:55)
at liquibase.snapshot.DatabaseSnapshot。< init> :在liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:126 25)
)在liquibase.snapshot.SnapshotGeneratorFactory.createSnapshot(SnapshotGeneratorFactory.java:119

在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添加到我的类路径中来实现它。这是超级混乱,没有很好的记录。
我经历的过程是:


  1. 下载正确的插件项目的源代码( https://github.com/liquibase/liquibase-hibernate/releases )在我的情况下,它是liquibase -hibernate4-3.5。


  2. 运行 mvn dependency:copy-dependencies 。这将它们转储到 / target / dependency / 中。将所有这些jar复制到你的 LIQUIBASE_HOME / lib 目录下。


  3. 所以我使用自定义任务来复制所有依赖项。如果您使用的是maven,您可以在自己的项目中使用与2相同的步骤来获取所有depdenencies。我将这些库从我的输出目录复制到 LIQUIBASE_HOME / lib 目录中。

     任务copyToLib(类型:复制){
    到$ buildDir / output / libs
    from configurations.runtime
    }
  4. 我也将正确的 hibernate-liquibase-4.3.5.jar 放入<$ c
    $ b $ p
    $ b

    这给了我所需的所有依赖关系为这个插件。



    这是一个令人讨厌的混乱球,但是你能做什么:($ / b>

    As described here (https://github.com/liquibase/liquibase-hibernate/issues/74) I'm having an issue getting the liquibase-hibernate extension to work properly. I think I have everything setup, but it seems like I keep running into weird problems. I feel like I'm missing something simple, but I think I've followed all the instructions as provided.

    I'm using liquibase 3.3.2, Hibernate 4.3.0.Final, java 1.7.0_71 and the liquibase-hibernate4-3.5.jar. My CLASSPATH environmental variable is empty, but some stuff gets added to it by the liquibase shell script. When I'm using normal liquibase commands interacting, and I remove the extension from $LIQUIBASE_HOME/lib/ directory without the extension it works just fine. I reran the commands with DEBUG output on to provide some more information.

    $ 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
    

    My liquibase.properties file

    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
    

    If I uncomment my referenceDriver I get this. Is there something I'm missing here? I thought I had all the required dependencies, and I'm not sure if this is some manifestation of the earlier problem where the extension could not load stuff properly.

    $ 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$1.run(URLClassLoader.java:366)
            at java.net.URLClassLoader$1.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
    

    After adding the hibernate jar to the liquibase/lib folder (which is really wrong) the error turned into this. I tried reverting to an older version of the plugin (while downgrading liquibase as well), and it did not help.

    $ 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
    

    解决方案

    I got it working by adding these jars to my classpath. This is super confusing and not well documented. The process I went through was:

    1. Download the source for the correct plugin project found here (https://github.com/liquibase/liquibase-hibernate/releases) in my case it was liquibase-hibernate4-3.5.

    2. Run mvn dependency:copy-dependencies. This dumps them into /target/dependency/. Copy all these jars and put them into your LIQUIBASE_HOME/lib directory.

    3. I'm using gradle so I used a custom task to copy all my dependencies. If you're using maven you can use the same step from 2 on your own project to fetch all your depdenencies. I copied these libs from my output directory into the LIQUIBASE_HOME/lib directory.

      task copyToLib(type: Copy) {
          into "$buildDir/output/libs"
          from configurations.runtime
      }
      

    4. I also put the correct hibernate-liquibase-4.3.5.jar into the LIQUIBASE_HOME/lib directory.

    That gave me all the dependencies I needed for the plugin.

    This is a big nasty ball of mess, but what can you do :(

    这篇关于Liquibase Hibernate插件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆