Envers 添加用户信息

Envers adding user information

我遇到了 Envers 的问题。首先,这是我的两个休眠 类:

child.java:

@Entity
@Audited
public class child {
    @Id
    private int id;
    private String text;
    @ManyToOne
    @JoinColumn(name="child")
    private testclass parent;
    public int getId() {return id;}
    public void setId(int id) {this.id = id;}
    public String getText() {return text;}
    public void setText(String text) {this.text = text;}
    public testclass getParent() {return parent;}
    public void setParent(testclass parent) {this.parent = parent;}
}

testclass.java:

@Entity
@Audited
public class testclass {
    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_template")
    @SequenceGenerator(name="seq_template", sequenceName="tester_seq")
    private int id;

    private String text;

    @OneToMany(mappedBy="parent")
    private Set<child> childs;

    public int getId() {return id;}
    public void setId(int id) {this.id = id;}
    public String getText() {return text;}
    public void setText(String text) {this.text = text;}
    public Set<child> getChilds() {return childs;}
    public void setChilds(Set<child> childs) {this.childs = childs;}
}

两个 类 都工作正常,审计信息,如时间戳存储得很好。

我现在想用审计信息用户名扩展信息。为此,我创建了这些配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="ch.triwdata.envers.extensions">
    <class name="ExtendedRevisionEntity" table="revinfo">
        <id name="id" type="int">
            <column name="rev" not-null="true"/>
            <generator class="native"/>
        </id>
        <property name="timestamp" type="long" column="timestamp" />
        <property name="username" type="string" not-null="true"/>
    </class>
</hibernate-mapping>

当然还有一个带有hibernate-configuration的配置文件,但我认为这在这里并不重要。

谁能看到我的失败,为什么没有存储用户信息?

此致 比约恩

PS: 也许这个 xml 不见了?当然,我从一开始就添加了它:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.password">****</property>
        <property name="connection.pool_size">1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create-drop</property>

        <mapping class="testclass"/>
        <mapping class="child"/>
    </session-factory>
</hibernate-configuration>

我明白了! :D

失败在这里:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.url">jdbc:postgresql://localhost/postgres</property>
        <property name="hibernate.connection.username">twd_genmeta</property>
<!--         <property name="hibernate.connection.driver_class">com.p6spy.engine.spy.P6SpyDriver</property> -->
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.password">Deliaa</property>
        <property name="connection.pool_size">1</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">create-drop</property>

        <mapping class="ch.triwdata.envers.classes.testclass"/>
        <mapping class="ch.triwdata.envers.classes.child"/>
        <mapping resource="hibernate.hbm.xml"/> <---- this entry is missing
    </session-factory>
</hibernate-configuration>

非常感谢您的回复!

此致 比约恩