让我们说我们有一个实体:无法addProjection到关系领域envers查询
@Entity
@Audited(withModifiedFlag = true)
public class MyEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false, length = 50)
private String Name;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parentEntityId")
private MyEntity parentEntity;
}
我尽量让上表示关系实体领域envers回报实体版本信息。我使用addProjection
来创建我自己的数据表示。问题是,每次我使用addProjection
时,表示关系的字段的名称出现错误(如果使用oridinary列,则没有错误)。
我建立一个审计查询:
AuditQuery auditQuery = reader.createQuery()
.forRevisionsOfEntity(MyEntity.class, false, true);
auditQuery.addProjection(AuditEntity.revisionNumber());
auditQuery.addProjection(AuditEntity.revisionType());
auditQuery.addProjection(AuditEntity.revisionProperty("timestamp"));
auditQuery.addProjection(AuditEntity.id());
auditQuery.addProjection(new AuditProperty<>(
new EntityPropertyName("parentEntity")));
auditQuery.addProjection(new AuditProperty<>(
new ModifiedFlagPropertyName(
new EntityPropertyName("parentEntity"))));
和错误是:
org.hibernate.QueryException: could not resolve property: parentEntity of: edu.sample.domain.entity.MyEntity_AUD
我也试过:new EntityPropertyName("parentEntityId")
- 结果是:
org.hibernate.QueryException: could not resolve property: parentEntityId of: edu.sample.domain.entity.MyEntity_AUD
编辑 : 我错过了Audit que中的一条语句RY。该投影应该包含parentEntity字段值,不仅修改标志: auditQuery.addProjection(new AuditProperty<>( new EntityPropertyName("parentEntity")));
我需要该字段的值和信息(如果它已被修改)。这就是为什么我使用withModifiedFlag = true
问题是MyEntity_AUD表(自动生成)的模式包含字段parentEntityId
。修改的标志字段名称是parentEntity_MOD
。添加到查询以下投影后的误差体现:
addProjection(new AuditProperty<>( new EntityPropertyName("parentEntity")));
或
addProjection(new AuditProperty<>( new EntityPropertyName("parentEntityId")));
的修改标志被正确无误返回。以及普通领域的价值。
当指定'selectOnlyEntities = false'时,为什么需要使用投影而不是使用返回的Object []',是否有一个特定的原因? – Naros