我正在使用massIndexer来索引我的文档。我有一种用 @transient注释的方法,该方法引用了懒惰的初始化@Onetomany集合:
@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 = fetchype.eager),我会得到此例外:
org.hibernate.LazyInitializationException:懒惰地初始化角色集合:&lt; ...>,无法初始化代理 - 没有会话
关于如何在不急切的情况下做到这一点的任何想法?(我有4或5个集合需要急切地提取,如果这没有不同的效果 ->巨大的性能问题)
预先感谢。
btw:我正在使用
<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,我们最近解决了。
如果没有其他方法来执行此操作,我将使用此工作策划(与第一个帖子不同)。但是我真的不喜欢它。
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();
}
}
,然后调用一种通过根豆的ID查询的方法。