我有一个定义如下的实体
@Entity(name = "Report")
@Table(name = "REPORTS")
@org.hibernate.annotations.Entity(dynamicInsert = true, dynamicUpdate = true, selectBeforeUpdate = true)
public class Report implements java.io.Serializable {
/* other fields, getters and setters*/
@Column(name = "UPD_TIMESTAMP")
@Version
private Long updTimestamp;
@OneToMany(mappedBy = "report", fetch = FetchType.LAZY)
private Collection<ReportItem> reportItems = new ArrayList<ReportItem>();
public Collection<ReportItem> getReportItems() {
return reportItems;
}
public void setReportItems(Collection<ReportItems> reportItems) {
this.reportItems = reportItems;
}
}
问题是,当我修改reportItems中的内容时,Report实体会变脏,并且始终存在仅增加版本字段的更新。
我知道@OptimisticLock(excluded = true),但是我坚持使用Hibernate 3.2.0 GA,并且此注释不可用。我可以在Hibernate 3.20 GA中使用此功能的任何解决方法吗?
最佳答案
看一下反向关键字,也许可以提供解决方案。 Here进行解释。
编辑:原来这是预期的行为。 See this question