【发布时间】:2015-12-14 04:44:49
【问题描述】:
我的项目中有几个由 Hibernate 处理的类,一些由 Envers 审计,一些则不是。现在,当我尝试保存某个未经审计的实体时,我得到了这个:
java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (no such table: audit_etc_etc)
有些人可能会认为我的数据库中没有审计表,但 Envers 甚至不应该尝试查找该表,因为该实体未经过审计。我的课程如下所示:
@Entity
class A {
/* some 'normal' attributes here */
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
AuditedEntity e;
List<B> listOfBs;
}
@Entity
class B {
/* more 'normal' attributes here */
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
AuditedEntity e; // and some more references to audited entities
A anA;
List<C> listOfCs;
}
@Entity
class C {
/* more 'normal' attributes here */
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
AuditedEntity e; // and some more references to audited entities
B anB;
}
所以每个类都有一个子类列表,其中包含对其父类的引用。这些类都没有使用@Audited-annotation 进行标记,但它们引用了一些经过审计的实体。然而,这些引用中的每一个都标有@Audited(targetAuditMode = RelationTargetAuditMode. NOT_AUDITED)-annotation。
我在 hibernate.cfg.xml 文件中也没有发现任何异常,只有连接详细信息、环境选项、类映射和其他一些休眠选项。
这里出了什么问题,我该如何解决保存时出现的这个问题?
(注意:我目前只对 A 类和 B 类进行了测试,但我认为尝试保存 C 的实例会引发相同的异常)
更新:
当我尝试保存 B 实例时,启用 show_sql 会显示:
Hibernate: update table_b set all_attributes=? where idB=?
Hibernate: insert into audit_description (timestamp, description) values (?, ?)
Hibernate: insert into audit_table_b (revision_type, attributes, moreAttributes, revision) values (?, ?, ?, ?)
【问题讨论】:
标签: java hibernate hibernate-envers