gpt4 book ai didi

hibernate - 创建初始索引时出现 TransientObjectException

转载 作者:行者123 更新时间:2023-12-04 17:20:30 25 4
gpt4 key购买 nike

我正在使用以下代码来初始化我的 Hibernate 搜索索引:

EntityManager em = ...
FullTextEntityManager fullTextEM = Search.getFullTextEntityManager(em);
fullTextEM.createIndexer().startAndWait();

现在,当我执行这段代码时,出现以下异常:

ERROR: HSEARCH000058: HSEARCH000116: Unexpected error during MassIndexer operation
org.hibernate.TransientObjectException: cannot lock an unsaved transient instance: com.example.hs.model.Division
at org.hibernate.event.internal.DefaultLockEventListener.onLock(DefaultLockEventListener.java:75)
at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:724)
at org.hibernate.internal.SessionImpl.fireLock(SessionImpl.java:717)
at org.hibernate.internal.SessionImpl.access$1700(SessionImpl.java:170)
at org.hibernate.internal.SessionImpl$LockRequestImpl.lock(SessionImpl.java:2276)
at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.indexAllQueue(EntityConsumerLuceneWorkProducer.java:130)
at org.hibernate.search.batchindexing.impl.EntityConsumerLuceneWorkProducer.run(EntityConsumerLuceneWorkProducer.java:102)
at org.hibernate.search.batchindexing.impl.OptionallyWrapInJTATransaction.run(OptionallyWrapInJTATransaction.java:112)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)

在这种情况下,com.example.hs.model.Division 类确实有两个 @Transient 注释用于从 计算返回值的方法 HashMap HashMap 通过 Hibernate 检索如下:

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "division_id", referencedColumnName = "id")
@MapKey(name = "language")
@Field(name="name")
@FieldBridge(impl = com.example.hs.search.LanguageDivisionTextBridge.class)
protected Map<Language, DivisionText> getDivisionTextMap() {
return divisionTextMap;
}

如您所见,我正在使用自定义 FieldBridge 来帮助映射。 DivisionText 类也标有 @Indexed 注释并已成功建立索引。

完整的源代码集可以在以下位置找到:

https://github.com/jsvazic/hibernate-search-example

如有任何帮助,我们将不胜感激。

最佳答案

您的问题与 Foo, 中的 @Transient 注释无关,而是与整个 Foo 相关。索引过程中的一些代码试图调用 Session.lock(foo), 但此时 foo 仍然只是一个普通对象,在被分配给使用 Session.saveSession.persist 的 session 。如 here 所述,将 cascade=PERSIST 参数添加到父对象中 foo 字段的注释中可能会有所帮助.

关于hibernate - 创建初始索引时出现 TransientObjectException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10035825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com