gpt4 book ai didi

java - 恩弗斯添加用户信息

转载 作者:行者123 更新时间:2023-12-01 11:20:01 25 4
gpt4 key购买 nike

我遇到了恩弗斯的问题。首先,这是我的两个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com