gpt4 book ai didi

java - org.hibernate.QueryException : could not resolve property: createdDate_MOD of: org. baeldung.HibernateAuditDemo.model.Order_AUD

转载 作者:搜寻专家 更新时间:2023-11-01 03:36:43 33 4
gpt4 key购买 nike

我使用 hibernate envers 进行审计。

我有简单的Order实体:

@Entity
@Table(name = "orders")
@Audited
public class Order {

@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
private Long id;

private Double price;

@Temporal(TemporalType.TIMESTAMP)
private Calendar createdDate;

public Order() {
}
//the rest is unimportant

我使用 AuditorReader查询属性已更改的修订:

    AuditReader auditReader = AuditReaderFactory.get(entityManager);
// find revision at which order entity changed its property createdDate
List revisions = auditReader.createQuery().forRevisionsOfEntity(Order.class, false, true).
add(AuditEntity.property("createdDate").hasChanged()).getResultList();

Object[] history = (Object[]) revisions.get(0);

在这段代码中我得到异常:

org.hibernate.QueryException: could not resolve property: createdDate_MOD of: org.baeldung.HibernateAuditDemo.model.Order_AUD [select e__, r from org.baeldung.HibernateAuditDemo.model.Order_AUD e__, org.hibernate.envers.DefaultRevisionEntity r where e__.createdDate_MOD = :_p0 and e__.originalId.REV.id = r.id order by e__.originalId.REV.id asc]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1967)

在表中的数据库中ordersorders_aud ,我看到名为 createdDate 的列但不是 createdDate_MOD .

为什么不能属性createdDate解决了吗?

最佳答案

要让 hibernate envers 跟踪对某些属性的更改,您需要在该属性上设置 @Audited(withModifiedFlag = true)

要为所有实体全局设置它,您需要在 hibernate 属性中将 org.hibernate.envers.global_with_modified_flag 设置为 true。

关于java - org.hibernate.QueryException : could not resolve property: createdDate_MOD of: org. baeldung.HibernateAuditDemo.model.Order_AUD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29520056/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com