【问题标题】:Liquibase:diff - Unsupported property type for generator annotation @CreationTimestamp on ZonedDateTimeLiquibase:diff - ZonedDateTime 上的生成器注释 @CreationTimestamp 不支持的属性类型
【发布时间】:2019-06-03 03:04:28
【问题描述】:

我有一个实体,其 ZonedDateTime 归档并带有 @CreationTimestamp 注释:

@CreationTimestamp
@Column(name = "created")
private ZonedDateTime created;

运行时:

mvn liquibase:diff

我收到以下错误:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.5:diff (default-cli) on project myproject: Error setting up or running Liquibase: org.hibernate.HibernateException: Unsupported property type for generator annotation @CreationTimestamp -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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 read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是我在 pom.xml 中的 hibernate 和 liquibase 依赖项:

<!-- The hibernate version should match the one managed by
https://mvnrepository.com/artifact/io.github.jhipster/jhipster-dependencies/${jhipster-dependencies.version} -->
<hibernate.version>5.2.12.Final</hibernate.version>

<!-- The liquibase version should match the one managed by
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-dependencies/${spring-boot.version} -->
<liquibase.version>3.5.5</liquibase.version>
<liquibase-hibernate5.version>3.6</liquibase-hibernate5.version>

@CreationTimeStamp 用于 ZonedDateTime 字段的正确版本是什么?

【问题讨论】:

  • 我发现的唯一解决方法是在运行 liquibase:diff 命令之前删除注释,然后将其放回原处。仍然不支持 ZonedDateTime,即使使用 hibernate 5.4.0.final ?

标签: java hibernate maven jhipster liquibase


【解决方案1】:

可以使用对象设置器的解决方法:

public void setDateCreated(Object object) {
        if (object.getId() == null) {
            // which will run only when the object is new
            this.dateCreated = Instant.now();
        }
    }
public void setDateUpdated() {
        // which runs everytime the object is updated
        this.dateUpdated = Instant.now();
    }

或者您可以在运行更改差异之前手动设置 liquibase 更改日志上的 valueDate 属性:

<column name="Join_date" valueDate="${now}"/>

或者在运行 liquibase diff 时注释掉注释,并在完成后将它们添加回来。

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2019-03-24
    • 1970-01-01
    • 2014-09-08
    • 1970-01-01
    • 2021-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多