Envers添加用户信息

时间:2015-07-11 12:26:13

标签: java hibernate hibernate-envers

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

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配置的配置文件,但我认为这不重要。

有人可以看到我的失败,为什么没有存储用户信息?

祝你好运 的Björn

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>

1 个答案:

答案 0 :(得分:1)

我明白了! :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>

非常感谢您的回复!

祝你好运 的Björn