java - 恩弗斯添加用户信息

标签 java hibernate hibernate-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;}
}

测试类.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>

非常感谢您的回复!

最诚挚的问候 比约恩

关于java - 恩弗斯添加用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31357168/

相关文章:

java - 使用java Scanner获取字符串中的标记数量

java - 如何让 2 个 HtmlUnit WebClient 使用相同的 cookie?

mysql - 如何将关系表建模为 Hibernate 中的实体

java - Hibernate Envers - 包括更改发生的日期

hibernate - 如何使用 hibernate 环境获取审计表的行数

java - 接口(interface)的多个实现者。 OSGi 怎么样?

java - Openshift 远程 EJB

hibernate - Grails:复杂的多对多 GORM 查询

java - 组织.hibernate.InstantiationException : Cannot instantiate abstract class or interface

mysql - 恩弗斯 + MYSQL + 列表 <字符串> = SQLSyntaxErrorException : Specified key was too long;