我正在尝试让一个简单的envers示例起作用。我有 Java 代码工作(显然),我终于让 org.hibernate.tool.ant.EnversHibernateToolTask 工作,但它只输出“常规”数据的 SQL,而不是版本控制数据。我很困惑下一步该做什么。
我可能会忘记包括什么?
这是它输出的 SQL:{versioning-ddl.sql}
create table Event (
id bigint generated by default as identity (start with 1),
date timestamp,
title varchar(255),
primary key (id)
);
create table Person (
id bigint generated by default as identity (start with 1),
age integer not null,
firstname varchar(255),
lastname varchar(255),
primary key (id)
);
create table PersonEvent (
eventID bigint not null,
personID bigint not null,
primary key (eventID, personID)
);
alter table PersonEvent
add constraint FK489E5C25F6E47374
foreign key (personID)
references Event;
alter table PersonEvent
add constraint FK489E5C25729F3820
foreign key (eventID)
references Person;
我没有看到任何历史记录表/字段。以下是我的 hibernate.cfg.xml 文件中的相关条目:
<hibernate-configuration>
<session-factory>
...
<property name="hibernate.ejb.event.post-insert">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-update">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-delete">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.pre-collection-update">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.pre-collection-remove">org.hibernate.envers.event.AuditEventListener</property>
<property name="hibernate.ejb.event.post-collection-recreate">org.hibernate.envers.event.AuditEventListener</property>
<mapping class="com.example.test.hibernate.test1.Event"/>
<mapping class="com.example.test.hibernate.test1.Person"/>
</session-factory>
</hibernate-configuration>
和 Java 类的相关部分:
@Entity
@Audited
public class Event {
@Id
@GeneratedValue
private Long id;
private String title;
private Date date;
...
}
@Entity
@Audited
public class Person {
@Id
@GeneratedValue
private Long id;
private int age;
private String firstname;
private String lastname;
...
}