Hibernate Envers:使用集合属性检索实体的正确修订 [英] Hibernate Envers: Retrieving the right revisions of an entity with a collection property

查看:129
本文介绍了Hibernate Envers:使用集合属性检索实体的正确修订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个审计实体,A和B.实体A拥有实体B的集合(注释为一对多关系)。当向数据库中插入一个新的A实例时,A和B的所有行都处于相同的修订版本(假设版本1)。然后,A上的更新只影响实体B的实例。因此,在更新之后,实体A仍处于修订版本1,而B的实体处于修订版本2(包括审计表中的MOD条目) 。在修订版3中,实体A被删除。由于实体B的集合由@Cascade注释,因此属于A的实体B也被删除。

鉴于这种情况,我如何使用Envers创建一个审计查询,以获取修订版本2的更新实体B的实体A的实例?当我查询实体A的所有修订版本时,我要么获得不包含B实体(修订版本3)的A的已删除实体,要么获得包含修订版本1的B实体的修订版本1的A。



使用Hibernate 3.6,如果有帮助的话。

解决方案

修订版2中,您将获得正确的数据。



目前没有办法获得实体或相关实体更改的修订列表(正如您的情况 - rev 2是仅在B中改变的,而不是在a)中。

I have two audited entities, A and B. Entity A holds a collection of entity B (annotated as One-to-many relationship). When inserting a new instance of A into the database, all rows of A and B are at the same revision (let's say revision 1). Then, there is an update on A which only affect the instances of entity B. So after the update, the entity A is still at revision 1, whereas the entities of B are at revision 2 (including a MOD entry in the audit table). In Revision 3, the entity A is deleted. Because the collection of entity B is annotated with @Cascade, the entities B belonging to A are deleted as well.

Given this scenario, how to I create an audit query with Envers that gets an instance of entity A with the updated entities B of revision 2? When I query for all revisions of entity A, I either get the deleted entity of A which holds no entities of B (revision 3), or I get A of revision 1 which holds B entities of revision 1, too.

Using Hibernate 3.6, if that helps.

解决方案

If you read entity A at revision 2, you will get the right data.

There is no way currently to get a list of revisions where an entity or related entities changed (as is your case - rev 2 is a change only in B, not in a).

这篇关于Hibernate Envers:使用集合属性检索实体的正确修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆