尝试运行liquibase diff时出现NullPointerException

时间:2015-09-24 03:56:59

标签: hibernate jpa spring-boot liquibase

我们在项目中使用spring boot和hibernate。我决定使用liquibase进行数据库迁移。当我尝试运行 mvn liquibase:diff 以产生JPA实体和现有数据库之间的差异时,我遇到 NullPointerException

liquibase.properties:

    changeLogFile=classpath:liquibase-changeLog.xml
    url=jdbc:oracle:thin:@localhost:1521:orcl
    username=xxxxxxx
    password=xxxxxxx
    driver=oracle.jdbc.OracleDriver
    referenceUrl=hibernate:spring:xxxxx.xxxxxxxxx.businesslogic.db.entity?dialect=org.hibernate.dialect.Oracle10gDialect
    diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
    outputChangeLogFile=src/main/resources/liquibase-outputChangeLog.xml

pom是:

<build>
    <plugins>
        <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>3.4.1</version>
            <configuration>
                <propertyFile>src/main/resources/liquibase.properties</propertyFile>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate4</artifactId>
                    <version>3.5</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                    <version>4.1.7.RELEASE</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.data</groupId>
                    <artifactId>spring-data-jpa</artifactId>
                    <version>1.7.3.RELEASE</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

因此我得到了:

...
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column allowNonWhole varchar2(2
55 CHAR)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column category varchar2(255 CH
AR)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column description varchar2(255
 CHAR)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column name varchar2(255 CHAR)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found table CatalogItem
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found primary key CatalogItemPK
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column itemId varchar2(255 CHAR
)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column created timestamp
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column updated timestamp
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column isActive number(1, 0)
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column itemDetails clob
INFO 9/23/15 8:34 PM: liquibase-hibernate: Found column catalog_id number(19, 0)

INFO 9/23/15 8:34 PM: liquibase: Can not use class liquibase.serializer.core.jso
n.JsonChangeLogSerializer as a Liquibase service because org.yaml.snakeyaml.repr
esenter.Representer is not in the classpath
INFO 9/23/15 8:34 PM: liquibase: Can not use class liquibase.serializer.core.yam
l.YamlChangeLogSerializer as a Liquibase service because org.yaml.snakeyaml.repr
esenter.Representer is not in the classpath
INFO 9/23/15 8:34 PM: liquibase: src\main\resources\liquibase-diff-changeLog.xml
 exists, appending
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.257 s
[INFO] Finished at: 2015-09-23T20:34:45-07:00
[INFO] Final Memory: 37M/315M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:diff (
default-cli) on project businesslogic: Error setting up or running Liquibase: li
quibase.command.CommandExecutionException: java.lang.NullPointerException -> [He
lp 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.liquibase:liquibase-maven-plugin:3.4.1:diff (default-cli) on project business
logic: Error setting up or running Liquibase: liquibase.command.CommandExecution
Exception: java.lang.NullPointerException
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:216)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProje
ct(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThre
adedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(Lifecycl
eStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Laun
cher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.jav
a:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(La
uncher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:
356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error setting up or r
unning Liquibase: liquibase.command.CommandExecutionException: java.lang.NullPoi
nterException
        at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiq
uibaseMojo.java:398)
        at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.execute(LiquibaseDa
tabaseDiff.java:146)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(Default
BuildPluginManager.java:132)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor
.java:208)
        ... 19 more
Caused by: liquibase.exception.LiquibaseException: liquibase.command.CommandExec
utionException: java.lang.NullPointerException
        at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(
CommandLineUtils.java:197)
        at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(
CommandLineUtils.java:174)
        at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.performLiquibaseTas
k(LiquibaseDatabaseDiff.java:182)
        at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiq
uibaseMojo.java:394)
        ... 22 more
Caused by: liquibase.command.CommandExecutionException: java.lang.NullPointerExc
eption
        at liquibase.command.AbstractCommand.execute(AbstractCommand.java:13)
        at liquibase.integration.commandline.CommandLineUtils.doDiffToChangeLog(
CommandLineUtils.java:195)
        ... 25 more
Caused by: java.lang.NullPointerException
        at java.util.Arrays$ArrayList.<init>(Arrays.java:2842)
        at java.util.Arrays.asList(Arrays.java:2828)
        at liquibase.diff.output.changelog.core.MissingPrimaryKeyChangeGenerator
.fixMissing(MissingPrimaryKeyChangeGenerator.java:76)
        at liquibase.diff.output.changelog.ChangeGeneratorChain.fixMissing(Chang
eGeneratorChain.java:48)
        at liquibase.diff.output.changelog.ChangeGeneratorFactory.fixMissing(Cha
ngeGeneratorFactory.java:99)
        at liquibase.diff.output.changelog.DiffToChangeLog.generateChangeSets(Di
ffToChangeLog.java:140)
        at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog
.java:120)
        at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog
.java:76)
        at liquibase.diff.output.changelog.DiffToChangeLog.print(DiffToChangeLog
.java:59)
        at liquibase.command.DiffToChangeLogCommand.run(DiffToChangeLogCommand.j
ava:61)
        at liquibase.command.AbstractCommand.execute(AbstractCommand.java:8)
        ... 26 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionE
xception

显然,插件定位JPA实体并能够将它们与数据库进行比较,但在尝试生成更改日志时出现问题。

有任何建议如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。显然, liquibase-maven-plugin v.3.4。* 出了问题。我只需要在上面的pom文件中将版本更改为 3.3.5 ,它就可以了。虽然它没有正常工作 - 我有一个JPA实体CatalogItem,hibernate从中创建CATALOG_ITEM数据库表,但之后我运行mvn liquibase:diff,而不是没有这个表的差异,pluign生成createTable更改为用于CATALOG_ITEM的CATALOGITEM DB表和dropTable,即 - liquibase hiberante maven插件不会将CatalogItem实体识别为CATALOG_ITEM DB表的ORM模型。

我会将此答案标记为正确,因为严格来说它会解决原始问题......