我有一个实体,其中有一个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 中有我的休眠和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字段的正确版本是什么?
答案 0 :(得分:0)
可以使用对象设置器的解决方法:
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时注释掉注释,并在完成后将其重新添加。