为什么Hibernate Envers将Last_edited_by列值替换为“ API”
我有类似的类结构:
@Entity
@Data
@Table(name="person_dtl")
@Audited
@AuditTable(value="h$person_dtl")
public class Person extends AuditBaseEntity implements Serializable {
@Id
@Column(name="person_ID", nullable = false)
private String personID;
@Column(name="person_Name", nullable = false)
private String personName;
}
@Audited
@MappedSuperClass
@EntityListeners(AuditingEntityListener.class)
public abstract class AuditBaseEntity extends BaseEntity {
@Column(name = "created_by", nullable = false, updatable = false)
@CreatedBy
protected String createdBy;
@Column(name = "last_modified_by")
@LastModifiedBy
private String lastModifiedBy;
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
protected Date createdDate;
@Column(name = "last_modified_date")
@LastModifiedDate
private Date lastModifiedDate;
@PrePersist
public void onPrePersist() {
this.activeIndicator="A";
}
@PreRemove
public void onPreRemove() {
this.activeIndicator="I";
}
}
@Audited
@MappedSuperClass
public abstract class BaseEntity {
@Column(name = "active_ind", nullable = false)
@CreatedBy
protected String activeIndicator;
}
我一直在使用Hibernate Envers在Spring-Boot应用程序中进行审计。我在pom中包括了spring-data-jpa
和envers
依赖性。我明确设置了createby
和lastModifiedby
列的值,但是每当发生插入发生createby
and code> lastModifiedby 时列值在我们的Oracle DB中的表中设置为“ API”。同样,每当我执行更新lastModifiedby
列值时,即使我将用户ID设置在实体中,也将设置为“ API”。为什么会发生这种情况?我是否缺少某些财产价值?
I have class structure something like:
@Entity
@Data
@Table(name="person_dtl")
@Audited
@AuditTable(value="h$person_dtl")
public class Person extends AuditBaseEntity implements Serializable {
@Id
@Column(name="person_ID", nullable = false)
private String personID;
@Column(name="person_Name", nullable = false)
private String personName;
}
@Audited
@MappedSuperClass
@EntityListeners(AuditingEntityListener.class)
public abstract class AuditBaseEntity extends BaseEntity {
@Column(name = "created_by", nullable = false, updatable = false)
@CreatedBy
protected String createdBy;
@Column(name = "last_modified_by")
@LastModifiedBy
private String lastModifiedBy;
@Column(name = "created_date", nullable = false, updatable = false)
@CreatedDate
protected Date createdDate;
@Column(name = "last_modified_date")
@LastModifiedDate
private Date lastModifiedDate;
@PrePersist
public void onPrePersist() {
this.activeIndicator="A";
}
@PreRemove
public void onPreRemove() {
this.activeIndicator="I";
}
}
@Audited
@MappedSuperClass
public abstract class BaseEntity {
@Column(name = "active_ind", nullable = false)
@CreatedBy
protected String activeIndicator;
}
I've been using hibernate envers to for auditing purpose in my spring-boot app. I have included spring-data-jpa
and envers
dependency in pom. I am explicitly setting values of createdBy
and lastModifiedBy
columns to user's id but whenever the insert is happening createdBy
and lastModifiedBy
column values are being set to "API" in the table in our Oracle DB. Also whenever I am performing update lastModifiedBy
column value is being set to "API" even though I have set userid in my entity. Why is this happening? Am I missing some property value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是弹簧数据,因此用
@createdby @lastmodifiedby
注释的实体将被当前记录的用户填充。您可以覆盖此行为,并告诉Spring在数据库中插入新记录时存储当前的用户ID。为此,您将需要提供
auditoraware
接口和OverridegetCurrentAuditor()
方法的实现。内部getCurrentAuditor()
您需要获取当前登录用户的ID。Since you are using Spring Data, entities annotated with
@CreatedBy @LastModifiedBy
are going to be populated with the currently logged user.You can override this behaviour and tell Spring to store current user id whenever you insert new record in database. To achieve that you will need to provide an implementation of
AuditorAware
interface and overridegetCurrentAuditor()
method. InsidegetCurrentAuditor()
you will need to fetch currently logged in user 's id.