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

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

问题描述

在 Hibernate Envers 中,一个实体的所有相关集合都被延迟加载,而不管设置的获取类型是什么.因此,当对具有其他实体集合(当然都经过审核)的实体进行审计查询时,该集合首先是一个 SetProxy(调试时可以看到).

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).

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

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.

我需要急切地初始化它们,因为我将在稍后 Hibernate 会话已经关闭(将域对象转换为 dtos)时访问集合.

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).

我使用的是 Hibernate 3.5.6.

I'm using Hibernate 3.5.6.

推荐答案

显然,这是 Hibernate Envers 的一个悬而未决的问题.他们的 JIRA 中已经存在一个问题:https://hibernate.atlassian.net/browse/HHH-3552.随意投票,也许它会加快速度,当他们看到有些人希望修复此问题时;)

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 ;)

在 Envers 团队解决此问题之前,有一种解决方法对我有用:在集合上调用 size() 会初始化代理对象.

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天全站免登陆