如果我设置 hibernate.jpa.compliance.query=true 那么我得到:
org.hibernate.query.sqm.StrictJpaComplianceViolation: Encountered FQN entity name [gbt.osmoze.model.osmoze.audit.CustomRevEntity], but strict JPQL compliance was requested ( [CustomRevEntity] should be used instead )
要求是:
org.hibernate.envers.AuditReader reader;
Long id;
@SuppressWarnings("unchecked")
List<Object[]> list = reader.createQuery()
.forRevisionsOfEntity(clazz, false, true)
.add(AuditEntity.id().eq(id))
.getResultList();
使用自定义修订实体:
package gbt.osmoze.model.osmoze.audit
@Entity
@Table(name="Revision_Infos")
@RevisionEntity(CustomRevisionListener.class)
public class CustomRevEntity implements Serializable, RevEntity {
private static final long serialVersionUID = 1L;
@Id
@Column(name="revision_id")
@RevisionNumber
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "RevisionInfosSequence")
@SequenceGenerator(name = "RevisionInfosSequence", sequenceName = "Revision_Infos_SEQ", allocationSize = 1)
private long revisionId;
@Column(name="epoch_timestamp")
@RevisionTimestamp
private long epochTimestamp;
@Convert(converter=gbt.model.converter.TimestampToInstantConverter.class)
@Column(name="timestamp")
private Instant timestamp;
@Column(name="user_id")
private String userId;
// rest omitted
}
如果
hibernate.jpa.compliance.query=false
那么它工作正常并且查询是:
SELECT o1_0.REV,
o1_0.ordre_operation_id,
o1_0.ordre_operation_type,
o1_0.REVTYPE,
o1_0.cancelled_by_operation_id,
o1_0.comment,
o1_0.comment_source,
c1_0.revision_id,
c1_0.epoch_timestamp,
c1_0.timestamp,
c1_0.user_id
FROM Ordre_Operations_AUD o1_0,
Revision_Infos c1_0
WHERE o1_0.ordre_operation_id=?
AND o1_0.REV=c1_0.revision_id
ORDER BY o1_0.REV
那么是否可以在
hibernate.jpa.compliance.query
设置为 true 的情况下与 Envers 一起工作?
我使用 wildfly-29.0.1.Final 和 hibernate-envers 6.2.6.Final
我认为该行为是由 envers 内部生成 HQL 引起的,它使用实体的完全限定类名,这显然不符合
hibernate.jpa.compliance.query=true