标签: liquibase-hibernate

liquibase-hibernate5无法与liquibase-maven-plugin一起使用

我正在使用Spring Boot Starter 1.4.2.RELEASE + Hibernate 5 + Hibernate Spatial + Liquibase 3.5.3 + Liquibase Hibernate 5(liquibase-hibernate5 3.6)+ PostgreSQL,但我无法使liquibase:diff目标工作。

这是我的设置:

      <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <dependencies>
                <dependency>
                    <groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId>
                    <version>1.1.0.Final</version>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-spatial</artifactId>
                    <version>${hibernate.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
                    <version>3.18.2-GA</version>
                </dependency>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate5</artifactId>
                    <version>${liquibase-hibernate5.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.postgresql</groupId>
                    <artifactId>postgresql</artifactId>
                    <version>${postgresql.driver.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                    <version>${project.parent.version}</version>
                </dependency>
            </dependencies>
            <configuration>
                <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                <diffExcludeObjects>geography_columns, geometry_columns, raster_columns,
                    raster_overviews, spatial_ref_sys</diffExcludeObjects>
                <driver>org.postgresql.Driver</driver>
                <url>jdbc:postgresql://localhost:5432/mydb?useUnicode=true&amp;characterEncoding=utf8</url>
                <!--<defaultSchemaName></defaultSchemaName>-->
                <username>myusr</username>
                <password>mypwd</password>

                <referenceUrl>hibernate:spring:my.package.with.domain?dialect=org.hibernate.spatial.dialect.postgis.PostgisDialect</referenceUrl>
                <verbose>true</verbose>
                <logging>debug</logging>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

运行mvn clean compile liquibase:diff -X给我以下异常:

. …
Run Code Online (Sandbox Code Playgroud)

spring hibernate liquibase spring-boot liquibase-hibernate

5
推荐指数
1
解决办法
1433
查看次数

为多个模式中的实体生成Liquibase-hibernate changelog

我试图使用liquibase-hibernate5(Spring-5.0.4.RELEASE,Hibernate-5.2.15)通过liquibase-maven-plugin在Hibernate实体(来自单个基本包)和干净数据库(Oracle 11gR2 XE)之间生成差异.最后,JPA-2.1.1应用程序通过servlet 3.1与所有(完整)程序配置).我使用JSON作为更改日志格式,liquibase-hibernate5(v3.6)使用liquibase-maven-plugin(v3.5.5).配置中使用的JPA规范版本是2.1.1.来自POM的片段:

            <plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.mvn.plugin.version}</version>
            <dependencies>
                <dependency>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-core</artifactId>
                    <version>${liquibase.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate5</artifactId>
                    <version>${liquibase.hibernate.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-beans</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-orm</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context-support</artifactId>
                    <version>${spring.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>javax.persistence</artifactId>
                    <version>${jpa.version}</version>
                </dependency>
                <dependency>
                    <groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId>
                    <version>${validation.api.version}</version>
                </dependency>
                <dependency>
                    <groupId>com.oracle.jdbc</groupId>
                    <artifactId>ojdbc8</artifactId>
                    <version>${jdbc.driver.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.yaml</groupId>
                    <artifactId>snakeyaml</artifactId>
                    <version>${snakeyaml.version}</version>
                </dependency>
            </dependencies>
            <configuration>
                <propertyFile>src/main/resources/jdbc/schema/liquibase.properties</propertyFile>
                <propertyFileWillOverride>true</propertyFileWillOverride>
                <promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>diff</goal>
                        <goal>update</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

这是我目前的liquibase.properties:

url: jdbc:oracle:thin:@localhost:1521/xe
username: db_user
password: password
driver: oracle.jdbc.OracleDriver
referenceUrl: hibernate:spring:org.example.something.entities?dialect=org.hibernate.dialect.Oracle10gDialect …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate liquibase liquibase-hibernate

5
推荐指数
0
解决办法
820
查看次数

如何在Spring Boot中为开发和生产环境划分Liquibase软件包结构?

我的包结构如下:

在此处输入图片说明

/db.changelog/db.changelod-master.xml中,我包含/db.changelog/v1/db.changelog-1.0.xml,其中,我还包括/db.changelog/v1/changeset软件包中的所有更改日志。

在我的应用程序中,我有两个配置文件:devprod,我需要根据Liquibase的“最佳实践”划分软件包的结构。有些变更日志可以在产品开发环境中使用。

另外,我可以在changeset标记中使用context属性并显式设置devprod值,但是这种解决方法不是可取的。

简单用法如下:我切换到产品概要文件,并且将不会创建某些表,或者会跳过对数据库的某些插入。

您能帮我根据Liquibase“最佳实践”重构软件包的结构吗?

java spring liquibase spring-boot liquibase-hibernate

5
推荐指数
1
解决办法
1284
查看次数

通过 Spring Data JPA 在实体类中更改时,Liquibase 不更新列数据类型

在 Spring Boot, Spring Data JPA 项目中,我有一个名为Country的实体类,列数很少。我生成了更改日志并使用以下命令应用它

$ mvn process-test-resources

$ mvn process-resources
Run Code Online (Sandbox Code Playgroud)

它使用 liquibase 和 liquibase-hibernate5 插件创建表

国家.java

package com.liquibasedemo.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import javax.persistence.*;


@Entity
@Table(name = "country")
@Data
public class Country
{
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "name")
    private String name;

    @Column(name = "code")
    private String code;

    @Column(name = "iso_code")
    private String isoCode;

    @Column(name = "test_code")
    private String testCode;


    @ManyToOne
    @JoinColumn(name = "region_id")
    @JsonIgnore
    private Region region; …
Run Code Online (Sandbox Code Playgroud)

java liquibase spring-data-jpa liquibase-hibernate

4
推荐指数
1
解决办法
1624
查看次数

使用 liquibase-hibernate 插件时出现“找不到数据库驱动程序:未指定驱动程序类且无法从 url 确定”错误

我正在尝试changeLogdiff数据库和持久性实体之间的 s 生成。

我正在使用 liquibase hibernate 插件

<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> 
Run Code Online (Sandbox Code Playgroud)

我的liquibase.properties情况是这样的

changeLogFile=classpath:liquibase-changeLog.xml
url=jdbc:postgres://localhost:5432/oauth_reddit
username=tutorialuser
password=tutorialmy5ql
driver=org.postgresql.Driver
referenceUrl=com.sample.App
  ?dialect=org.hibernate.dialect.PostgreSQLDialect
diffChangeLogFile=src/main/resources/liquibase-diff-changeLog.xml
Run Code Online (Sandbox Code Playgroud)

执行时mvn liquibase:diff,我收到以下错误

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.4.1:diff (default-cli) on project prototype-liquibase-migration: Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified …
Run Code Online (Sandbox Code Playgroud)

liquibase liquibase-hibernate

4
推荐指数
1
解决办法
1万
查看次数

无法通过 Spring Hibernate 获得 Liquibase 工作

到目前为止,我已经将 liquibase 与 spring 和标准变更日志文件一起使用。现在我想将其集成到休眠中,因此当我对实体进行任何更改时,它应该更改表并更新更改日志表。

我读了很多例子和教程,但无法让它发挥作用。

我使用数据源,entityManagerFactory(denepds-on="liquibase") 都工作正常。但是当我添加 liquibase bean 时,它不会从实体更改数据库。并且抛出“没有名称的表”异常。

如何使用 liquibase-hibernate4 和 spring 配置 Liquibase?

我的液体基豆:

<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
      <property name="dataSource" ref="myJdbcDataSource" />
      <property name="beanName" value="entityManagerFactory" />
      <property name="changeLog" value="classpath:databaseChangeLog.sql" />
</bean>
Run Code Online (Sandbox Code Playgroud)

我刚刚从https://github.com/liquibase/liquibase-hibernate/wikihttp://www.liquibase.org/documentation/spring.html添加了 beanName prop 作为entityManagerFactory 。并做了我从这篇文章中可以理解的事情。

在这篇文章中,它提到我们应该使用三种变体之一

hibernate:spring:com/example/spring.xml?bean=sessionFactory
hibernate:spring:com.example?dialect=org.hibernate.dialect.MySQL5Dialect
hibernate:spring:com.example.employee,com.example.auction?dialect=org.hibernate.dialect.MySQL5Dialect
Run Code Online (Sandbox Code Playgroud)

但我不知道当我们使用 spring 时如何将它与 liquibase bean 一起使用

java spring hibernate liquibase liquibase-hibernate

2
推荐指数
1
解决办法
2986
查看次数

使用带有liquibase changeset context属性的spring boot配置文件来管理changset范围

我试图用spring boot和liquibase做一个概念验证应用程序.我基本上想要创建一个可以通过使用名为context的changeset属性管理liquibase更改集的spring boot应用程序,这样没有上下文的changeset可以应用于任何spring引导配置文件,而具有特定上下文的changeset(例如context ="dev")仅当该类型的弹簧引导配置文件处于活动状态时才会应用(例如spring.profiles.active = dev).

在我的应用程序中,我有以下弹簧配置文件 - > dev,prod(每个在应用程序yaml文件中正确指定,并在配置文件下指定了相关配置文件数据库凭据).我需要做些什么来完成这项工作.下面是我的application.yaml

spring:
  application:
    name: liquibase-spring-jpa-postgres-example
liquibase:
  change-log: db.changelog/db.changelog-master.xml

spring:
  profiles: dev
  datasource:
    url: jdbc:postgresql://localhost:5432/dev
    username: postgres
    password: password
    driver-class-name: org.postgresql.Driver

spring:
  profiles: ci
  datasource:
      url: jdbc:postgresql://localhost:5432/ci
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver

spring:
  profiles: qa
  datasource:
      url: jdbc:postgresql://localhost:5432/qa
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver

spring:
  profiles: production
  datasource:
      url: jdbc:postgresql://localhost:5432/prod
      username: postgres
      password: password
      driver-class-name: org.postgresql.Driver
Run Code Online (Sandbox Code Playgroud)

以下是当前的databaseChangeLog文件(如果我的弹簧配置文件是prod,则第二个更改集不应该运行).

<changeSet id="20161016_my_first_change" author="fike" context="dev, qa, ci, production">
    <sql>
        CREATE TABLE customer
        (
        id BIGSERIAL …
Run Code Online (Sandbox Code Playgroud)

postgresql liquibase spring-boot liquibase-hibernate

2
推荐指数
2
解决办法
7306
查看次数

使用 Liquibase 将列添加到表中

我是后端开发新手,目前正在尝试向我的 app_user 表添加一列。像下面这样。

- changeSet:
      id: 300520202335
      author: Malindu De Alwis
      changes:
        - addColumn:
            tableName: app_user
              columns:
              -column:
                name: address
                type: VARCHAR(255)
Run Code Online (Sandbox Code Playgroud)

它给出了这个错误

Caused by: org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
Run Code Online (Sandbox Code Playgroud)

在“reader”中,第 23 行,第 22 列:列:^

我使用 Spring boot 和 postgre sql。请尝试找出问题所在

jpa liquibase spring-data-jpa spring-boot liquibase-hibernate

2
推荐指数
1
解决办法
9263
查看次数

从 liquibase 脚本运行环境特定的更改

我们使用 liquibase 进行数据库版本控制。我们用它来将数据库更改部署到任何层,例如 TST、AT 和 PROD。我们构建一次并将相同的更改部署到任何地方,但我们有某些东西应该部署到特定层。我不确定这是否可能或不是

\n\n

例如

\n\n

让\xe2\x80\x99s 说我们将应用程序URL 存储在数据库中,并且每个环境(INT、UAT、PROD)都有\xe2\x80\x99s 拥有不同的应用程序URL。我们如何使用 liquibase 脚本来做到这一点?

\n

oracle liquibase liquibase-hibernate

1
推荐指数
1
解决办法
5535
查看次数