我正在使用以下代码初始化我的Hibernate Search索引:
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
注释。通过Hibernate检索HashMap
,如下所示:
@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
非常感谢任何帮助。
答案 0 :(得分:3)
您的问题与@Transient
内的Foo,
注释无关,而与Foo
整体无关。索引过程中的一些代码尝试调用Session.lock(foo),
,但在foo
仍然只是一个普通对象时,在使用Session.save
或{{1}分配给会话之前}。也许有助于在父对象的Session.persist
字段上为注释添加cascade=PERSIST
参数,如here所述。