jpa 重命名hib环境ID和时间戳列

kmbjn2e3  于 2023-01-05  发布在  其他
关注(0)|答案(2)|浏览(116)

我正在尝试向应用程序的审核添加自定义列。
我有一个自定义修订实体:

@Entity
@Table(name = "REVINFO")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity extends DefaultRevisionEntity {
    private String username;

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; }
}

持久化数据时,hib会向数据库发送以下查询:

insert into REVINFO (timestamp, username, id) values (?, ?, ?)

问题是REVINFO表没有id和timestamp字段,因此我得到了一个错误
SQL语法错误异常:ORA-00904:"ID":无效标识符
REVINTO表格如下所示:

我可以告诉hib将id和时间戳分别Map到REV和REVTSTMP列吗?
请帮忙,先谢了。

sf6xfgos

sf6xfgos1#

试试这个。

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

@Entity
@Table(name = "REVINFO")
@RevisionEntity(UserRevisionListener.class)
public class UserRevEntity extends DefaultRevisionEntity {
    @Column(name = "USERNAME")
    private String username;

    @Column(name = "REV")
    private Integer id;

    @Column(name = "REVTSTMP")
    private BigInteger timestamp;

    // Make getter and setters

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; }
}
dl5txlt9

dl5txlt92#

Attributes Override应该可以解决这个问题。
请尝试:

@AttributeOverrides({
    @AttributeOverride(name = "timestamp", column = @Column(name = "REVTSTMP")),
    @AttributeOverride(name = "id", column = @Column(name = "REV"))
})
public class UserRevEntity extends DefaultRevisionEntity {
   private String username;

    public String getUsername() { return username; }

    public void setUsername(String username) { this.username = username; 

}

相关问题