【问题标题】:Hibernate envers is not updating manually added columns in REVINFO with annotationHibernate envers 不会使用注释更新 REVINFO 中手动添加的列
【发布时间】:2017-01-04 08:53:16
【问题描述】:

我使用纯 java 来休眠独立应用程序和 Hibernate Envers 以获取对表列所做更改的更新,我使用 sql server 作为我的数据库,我是 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);
}
}

Hibernate.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 文件时,它会在用户名列上添加值, 但是当我使用注释来获取值时,时间取空值,因为它没有识别我添加的额外列属性,但是 使用注解时,会在用户名列中插入空值

在控制台上查看 sql 代码时,它会采用这样的值和注释

/* insert org.hibernate.envers.DefaultRevisionEntity
    */ insert 
    into
        REVINFO
        (REVTSTMP) 
    values
        (?)

表只有 3 列,1 列 REV,即自动增量,2 列 REVTSTMP,3 列 USERNAME,它不带用户名, 我错过了什么,如果您需要更多信息,请发表评论

【问题讨论】:

  • 已修复,愚蠢的错误,我的 cfg.xml DOCTYPE 有问题

标签: java sql-server hibernate


【解决方案1】:

我认为问题来自您的注释配置,因此可以发布您的 hbm.xml 文件和用于注释配置的类吗?

【讨论】:

  • 感谢您转发 vvs。我在上面的代码中添加了“hibernate.cfg.xml”文件。虽然我使用的是注释所以不需要创建“hbm.xml”文件。这个文件有问题吗
猜你喜欢
  • 2014-12-01
  • 2015-12-08
  • 2017-02-24
  • 2014-07-03
  • 2015-05-05
  • 2018-12-02
  • 2018-08-09
  • 1970-01-01
  • 2019-01-27
相关资源
最近更新 更多