我在项目中使用envers来审核数据。
现在我想通过审核查询访问更改的数据。
我的表的pojo类位于
之下@Entity
@Audited(withModifiedFlag=true)
@Table(name = "INSTRUMENT", uniqueConstraints = @UniqueConstraint(columnNames = "INSTRUMENT_NAME"))
public class Instrument implements java.io.Serializable {
private long instrumentId;
private String instrumentName;
private WorkflowState workflowState;
@Id
@Column(name = "INSTRUMENT_ID", unique = true, nullable = false, precision = 22, scale = 0)
public long getInstrumentId() {
return this.instrumentId;
}
public void setInstrumentId(long instrumentId) {
this.instrumentId = instrumentId;
}
@Column(name = "INSTRUMENT_NAME", unique = true, nullable = false, length = 50)
public String getInstrumentName() {
return this.instrumentName;
}
public void setInstrumentName(String instrumentName) {
this.instrumentName = instrumentName;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "STATUS", nullable = false)
public WorkflowState getWorkflowState() {
return this.workflowState;
}
public void setWorkflowState(WorkflowState workflowState) {
this.workflowState = workflowState;
}
}
现在我尝试使用审核查询
来访问它AuditQuery query = reader.createQuery().forRevisionsOfEntity(Instrument.class, false, true)
.add(AuditEntity.property("status").hasChanged());
List list= query.getResultList();
所以在访问 getResultList()时,它抛出异常如下
SqlExceptionHelper: Fail to convert to internal representation
我想通了,这是因为我的db Instrument.status 列是String数据类型。在这里,我正在使用Join。
所以请告诉我如何编写查询来解决这个问题
问题是如果我的表有外键(类属性具有连接依赖性),如何编写审计查询。
加入表 WorkflowState 描述如下
public class WorkflowState implements java.io.Serializable {
private BigDecimal stateId;
private Workflow workflow;
private String stateName;
//getters and setters
它也有一个连接列,即“工作流程”。
答案 0 :(得分:0)
使用workflowState
而不是status
。 API基于您指定属性名称而不是列名称。