关于java:Hibernate Search中的Transient方法在MassIndexing时引用代理 | 珊瑚贝

Transient method in Hibernate Search referencing proxy while MassIndexing


我正在使用 MassIndexer 来索引我的文档。我有一个用 @Transient 注释的方法,它引用了一个延迟初始化的 @OneToMany 集合,如下所示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
@OneToMany
@JoinColumns({
        @JoinColumn(name =“insertForeignKeyHere”, referencedColumnName =“insertPrimaryKeyHere”),… })
@NotFound(action = NotFoundAction.IGNORE)
public Set<AdditionalOption> getAdditionalOptions() {
    return this.additionalOptions;
}

@Transient
@IndexedEmbedded
public Set<AdditionalOption> getActiveAdditionalOptions() {
    Set<AdditionalOption> ret = new HashSet<>();
    //the next line produces the error
    for (AdditionalOption addOpt : this.getAdditionalOptions()) {
        //do stuff.
    }
    return ret;
}

每当我尝试使用 MassIndexer 索引此文档并且没有 @OneToMany(fetch = FetchType.EAGER) 时,我都会收到此异常:

org.hibernate.LazyInitializationException: 无法延迟初始化角色集合:<…>,无法初始化代理 – 没有会话

关于如何在不获取 EAGER 的情况下执行此操作有什么想法吗? (我有 4 或 5 个集合需要急切地获取,如果这没有不同 -> 巨大的性能问题)

提前致谢。

顺便说一句:我正在使用

1
2
3
<hibernate.version>4.3.1.Final</hibernate.version>
<hibernate.search.version>4.5.0.Alpha2</hibernate.search.version>
<lucene.version>3.6.2</lucene.version>

尝试使用 Hibernate Search 4.5.0.Final 版本:您似乎遇到了 HSEARCH-1260,这是我们最近解决的问题。

  • 何时将发布添加到 mvnrepository.org 的 maven 存储库?
  • 现在,我可以使用 jboss repo :)。
  • 那次发布的时机对我来说真是太棒了:)。谢了哥们。顺便说一句,我正在为 Hibernate-Search API 做一个很好的补充,我可以给你发一封电子邮件,这样你就可以看看它,然后告诉我,推送它是否值得一试?
  • 似乎这种方法在我的系统上消耗了太多内存,因为这些集合看起来非常大。我切换回我的方法,因为它不会消耗这么多的内存。它甚至使我的计算机崩溃,因为它(计算机)内存不足。
  • 我收回最后的评论。我只是在我的hibernate配置中有一个错误的 fetch_size 设置。
  • 当然!请将有关 API 的建议发送到邮件列表,或加入 IRC 聊天:hibernate.org/community
  • 我在 5.3.0.Final 上遇到了这个问题。但是在标有@Transactional 的单个异步索引保存上


如果没有其他方法可以做到这一点,我将使用这个解决方法(使用与第一次发布不同的 bean 类)。但我真的不喜欢它。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static FeatureValueRepository featureValueRepository;
private static final Lock featureValueRepositoryLock = new ReentrantLock();

private static FeatureValueRepository getFeatureValueRepository() {
    featureValueRepositoryLock.lock();
    try {
        if (featureValueRepository == null) {
            //ContextProvider is a custom class in our project
            featureValueRepository = ContextProvider.getContext().getBean(
                    FeatureValueRepository.class);
        }
        return featureValueRepository;
    } finally {
        featureValueRepositoryLock.unlock();
    }
}

然后调用一个通过根bean的id查询的方法。

  • 这似乎并没有让我在索引时获得太多性能。


来源:https://www.codenong.com/21408565/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9476.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?