简体   繁体   English

Liquibase Hibernate Java 8支持

[英]Liquibase Hibernate Java 8 support

I hope someone had the same problem before, and asking here is quicker than the trial and error. 我希望之前有人遇到同样的问题,并且在这里询问比试错更快。

I have a Java 8 project, where I am trying to use Liquibase, and generate my changelog from my Entities: 我有一个Java 8项目,我正在尝试使用Liquibase,并从我的实体生成我的更改日志:

liquibase --changeLogFile=changeLog.yaml 
          --url=hibernate:spring:com.example.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect 
          --logLevel=debug generateChangeLog

I got the following error: 我收到以下错误:

SEVERE 11/04/15 09:55: liquibase: Failed to scan classpath for unlisted classes
liquibase.exception.DatabaseException: javax.persistence.PersistenceException: Failed to scan classpath for unlisted classes
...
Caused by: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: file [.../Example.class]; ...

I compiled my project using Java 7, and liquibase works fine. 我使用Java 7编译了我的项目,liquibase运行正常。

Liquibase Version: 3.3.2 Liquibase版本:3.3.2
Liquibase Hibernate4.2 Version: 3.5 Liquibase Hibernate4.2版本:3.5

As liquibase is open source, I can try and rebuild it using Java 8, but I have no idea if it will help. 由于liquibase是开源的,我可以尝试使用Java 8重建它,但我不知道它是否会有所帮助。

The exception indicates that problem is in the class reader from Spring, are you using the recent Spring version? 异常表明问题出在Spring的类阅读器中,您使用的是最近的Spring版本吗? The recent spring works with all Java 6-8 so you should not have a problem if you upgrade the Spring. 最近的Spring适用于所有Java 6-8,所以如果你升级Spring就不会有问题。

Also, is your runtime Java 8 as well? 另外,您的运行时Java 8也是如此吗? You may have more than JVM installed, for example runtime is 7 but you use JDK8, you would be able to build your project using Java8 but of course it will not run in Java7 environment. 您可能安装了更多JVM,例如运行时为7但您使用JDK8,您可以使用Java8构建项目,但当然它不能在Java7环境中运行。

Eventually I have figured it out, though it was not so easy. 最终我已经弄明白了,虽然这并不容易。

As Zielu pointed out, the problem was with Spring version. 正如Zielu指出的那样,问题出在Spring版本上。 Not in my own project though, but in liquibase-hibernate. 不是在我自己的项目中,而是在liquibase-hibernate中。

So the solution was: 所以解决方案是:

  1. Download liquibase-hibernate source from github github下载liquibase-hibernate源代码
  2. Update hibernate and spring dependecies 更新hibernate和spring dependecies
  3. Build liquibase-hibernate jar 构建liquibase-hibernate jar
  4. Copy this freshly built jar to the liquibase CLI lib folder 将这个新构建的jar复制到liquibase CLI lib文件夹中
  5. In the liquibase CLI lib folder, update spring and hibernate libraries 在liquibase CLI lib文件夹中,更新spring和hibernate库

Run liquibase as above. 如上所述运行liquibase。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM