Hibernate Envers:初始化Envers代理 [英] Hibernate Envers: Initializing Envers Proxies

查看:134
本文介绍了Hibernate Envers:初始化Envers代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Hibernate Envers中,一个实体的所有相关集合都被懒惰地加载,无论设置了哪种获取类型。因此,当为具有其他实体集合的实体(当然,这两个实体都进行了审计)进行审查时,集合最初是一个 SetProxy (可在调试时看到)。



那么,我该如何初始化该代理?使用 Hibernate.initialize()没有任何作用(我怀疑是因为Hibernate和Envers使用不同的代理对象)。我知道我可以通过迭代它的项目来初始化集合,但这不是我的选择,因为我在一个实体中有多个集合,更不用说维护问题了。



我需要初始化它们,因为我在Hibernate会话已经关闭的时候访问集合(将域对象转换为dtos)。



显然,这是Hibernate Envers的一个公开问题。

他们的JIRA中已经存在一个问题: https://hibernate.atlassian.net/browse/ HHH-3552 。随意投票,也许它会加快速度,当他们看到有人希望这个问题得到解决;)

直到Envers团队修复这个问题问题,有一项工作适用于我:在集合上调用 size()来初始化代理对象。


In Hibernate Envers, all related collections of an entity are loaded lazily, regardless of what fetch type is set. So when auditquerying for an entity that has a collection of other entities (both audited, of course), the collection is a SetProxy at first (can be seen when debugging).

So, how do I initialize that proxy? Using Hibernate.initialize() has no effect (I suspect because Hibernate and Envers are using different proxy objects). I know I can initialize the set by iterating over its items, but that isn't an option for me because I have multiple collections in an entity and not to mention the maintenance issues.

I need to initialize them eagerly because I'm accessing the collection at a later point in time when the Hibernate session is already closed (converting the domain objects into dtos).

I'm using Hibernate 3.5.6.

解决方案

Apparently, this is an open issue with Hibernate Envers. There is already an existing issue in their JIRA: https://hibernate.atlassian.net/browse/HHH-3552. Feel free to vote on it, maybe it will speed things up, when they see that there are some people wanting this to be fixed ;)

Until the Envers team fixes this issue, there is a work around which works for me: Calling size() on the collections initializes the proxy objects.

这篇关于Hibernate Envers:初始化Envers代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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