Reputation: 163
We are using spring boot and hibernate in our project. I decided to use liquibase for DB migration. When I try to run mvn liquibase:diff in order to produce differences between the JPA entities and the exisiting DB I run into 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
The pom is:
<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>
and as a result I get:
...
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
Apparently, the plugin locates the JPA entities and is able to compare them with the DB, but something goes wrong when it tries to generate the change log.
Any suggestions how to resolve this?
Upvotes: 1
Views: 3115
Reputation: 163
I've resolved the problem. Apparently, there's something wrong with the liquibase-maven-plugin v.3.4.*. I just had to change the version to 3.3.5 in the pom file above and it worked. It doesn't work correctly though - I have a JPA entity CatalogItem, from which hibernate creates CATALOG_ITEM DB table, but after that when I run mvn liquibase:diff, instead of no diff for this table, the pluign generates createTable change for CATALOGITEM DB table and dropTable for CATALOG_ITEM, i.e. - the liquibase hiberante maven plugin doesn't recognize the CatalogItem entity as the ORM model for the CATALOG_ITEM DB table.
I will mark this answer as correct, because strictly speaking it addresses the original problem ...
Upvotes: 1