我正在使用纯java与hibernate envers一起休眠独立应用程序,以获取表列中所做更改的更新,我正在使用sqlserver作为我的数据库,我是envers的新手。
这是我的“customrevisionentity.java”
@Entity
@AuditTable("REVINFO")
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevisionEntity {
@Column (name = "USERNAME", length = 50)
private String username;
@Id
@GeneratedValue
@RevisionNumber
@Column (name = "REV", unique = true, nullable = false)
private int id;
@Temporal(TemporalType.DATE)
@Column (name = "REVTSTMP", nullable = false, length = 15)
@RevisionTimestamp
private Date timestamp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getTimestamp() {
return timestamp;
}
public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
customrevisionlistener.java
public class CustomRevisionListener implements RevisionListener {
public void newRevision(Object revisionEntity) {
CustomRevisionEntity revision = (CustomRevisionEntity) revisionEntity ;
String userName = Hibernate_Connection.getloggedUser();
revision.setUsername(userName);
}
}
休眠.cfg.xml
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://localhost:1433;instance=SQLEXPRESS_2012;DatabaseName=ETS_V11_DEV;integratedSecurity=true</property> -->
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> -->
<property name="show_sql">true</property>
<property name="use_sql_comments">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class= "Domain_hibernate_SQLServer.Domain"/>
<mapping class= "Domain_hibernate_SQLServer.CustomRevisionEntity"/>
</session-factory>
</hibernate-configuration>
问题:当使用hbm.xml文件时,它会在username列上添加值,但当我使用注解获取值时,time会使用null值,因为它无法识别我添加的额外列属性,但在使用注解时,它会在username列中插入null值
它在控制台上查看sql代码时,使用注解获取这样的值
/* insert org.hibernate.envers.DefaultRevisionEntity
*/ insert
into
REVINFO
(REVTSTMP)
values
(?)
表只有3列,1是rev,即autoincrement,2是revtstmp,nd 3rd是username,它没有使用username,我遗漏了什么,如果您需要更多信息,请发表评论
1条答案
按热度按时间xlpyo6sf1#
我认为问题来自于你的注解配置,所以你可以发布你的hbm.xml文件和anotation配置使用的类吗?