我有一个实体,它包含两个日期,fromDate 和 toDate,如果我不审核它,它可以完美运行,但是,如果我添加 @Audited 注释,我会收到以下错误:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1' for column 'from_date_mod' at row 1
我的实体是这样的:
@Entity
@Audited
public class MyEntity {
@Id
@GeneratedValue
private BigInteger id;
@NotNull
private Date fromDate;
private Date toDate;
....
}
我的 liquibase 脚本是这样的:
databaseChangeLog:
- changeSet:
id: 1
author: Manuel
changes:
- createTable:
tableName: my_table
columns:
- column:
name: id
type: BIGINT
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: from_date
type: datetime
constraints:
nullable: false
- column:
name: to_date
type: datetime
- changeSet:
id: 2
author: Manuel
comment: Create Hibernate Envers audit table for my_table
changes:
- createTable:
tableName: my_table_aud
columns:
- column:
name: id
type: BIGINT
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: rev
type: BIGINT
constraints:
nullable: false
primaryKey: true
foreignKeyName: my_table_aud_revinfo_fk
referencedTableName: revinfo
referencedColumnNames: rev
- column:
name: revtype
type: TINYINT
defaultValue: null
- column:
name: from_date
type: datetime
defaultValue: null
- column:
name: from_date_mod
type: datetime
defaultValue: null
- column:
name: to_date
type: datetime
defaultValue: null
- column:
name: to_date_mod
type: datetime
defaultValue: null
所以,它与@Audited 相关,因为如果我删除注释它就可以工作。
你知道我为什么会收到错误吗?如果可能的话,我不希望更改 MyEntity 类的字段的 java 类型。