我想为我的项目添加Liquibase DB迁移支持。它也使用Spring Boot。现在,我只想使用Hibernate和JPA实体类就可以在没有数据库连接的情况下生成变更日志。但这会引发错误:
mvn liquibase:generateChangeLog
[...]
Error setting up or running Liquibase: javax.persistence.PersistenceException: Unable to resolve persistence unit root URL: class path resource [] cannot be resolved to URL because it does not exist
[...]
我没有一个persistentunit XML文件,因为这些都是由Spring Boot在运行时完成的。 该项目是一个多模块项目。 Liquibase插件配置位于父POM中。实体位于子模块中。
这是Liquibase的Maven插件配置:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
</dependencies>
<configuration>
<url>hibernate:spring:org.kitodo.mediaserver.core.db.entities?dialect=liquibase.ext.hibernate.database.HibernateGenericDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</url>
<driver>liquibase.ext.hibernate.database.connection.HibernateDriver</driver>
</configuration>
</plugin>
如果我使用数据库连接而不是hibernate:spring:...可以。
如何仅通过具有实体来获得没有DB连接就生成的变更日志?
答案 0 :(得分:0)
我有同样的问题,要解决,我添加了包含您的实体的maven项目的依赖项。例如:
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>${liquibase.version}</version>
<dependencies>
<dependency>
<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-hibernate5</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<!-- Add your maven project which hosts your entities classes -->
<dependency>
<groupId>org.kitodo.mediaserver</groupId>
<artifactId>org.kitodo.mediaserver.core.db.entities</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<url>hibernate:spring:org.kitodo.mediaserver.core.db.entities?dialect=liquibase.ext.hibernate.database.HibernateGenericDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</url>
<driver>liquibase.ext.hibernate.database.connection.HibernateDriver</driver>
</configuration>
</plugin>