I am trying to use Liquibase together with JPA annotations, but I does not seem to work.
I've got a clean DB with no tables and one JPA entity in my project. When I run liquibase diff, it claims, that DB is up-to-date - but it is simply not true.
maven config for liquibase plugin:
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<changeLogFile>src/main/resources/liquibase/changelog.xml</changeLogFile>
<referenceUrl>hibernate:spring:com.mycompany.entity?dialect=org.hibernate.dialect.PostgreSQLDialect</referenceUrl>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432/liqubase-test</url>
<username>postgres</username>
<password>postgres</password>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate4</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.4.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
changelog.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
</databaseChangeLog>
and when I run generateChangeLog task:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building liqubase-sample 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.3.1:generateChangeLog (default-cli) @ liqubase-sample ---
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql://localhost:5432/liqubase-test
[INFO] Generating Change Log from database postgres @ jdbc:postgresql://localhost:5432/liqubase-test (Default Schema: public)
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd"/>
[INFO] Output written to Change Log file, null
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.213 s
[INFO] Finished at: 2015-01-10T14:47:24+01:00
[INFO] Final Memory: 9M/216M
[INFO] ------------------------------------------------------------------------
Liquibase is correctly comparing the target database schema against the changelog you've specified.... which is empty :-)
You need to do some extra work. The following article appears to do a good job in outlining a workflow for liquibase with Hibernate:
It appears overly complicated, but what liquibase is doing is capturing all changes to the schema. In a nutshell you need to bring you DB to the latest captured state, generate the delta and then add this delta into your source code.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With