Getting TransientObjectException when creating my initial index
I am using the following code to initialize the Hibernate search index:
EntityManager em = ...
FullTextEntityManager fullTextEM = Search.getFullTextEntityManager(em);
fullTextEM.createIndexer().startAndWait();
Now when I execute this code I am getting the following exception:
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)
In this case, the class com.example.hs.model.Division
has two @Transient
method annotations that calculate the return value from a HashMap
. HashMap
retrieved via Hibernate like this:
@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;
}
As you can see, I am using a custom FieldBridge
one to help with the mapping. The class is DivisionText
also annotated @Indexed
and indexed successfully.
A complete set of sources can be found at:
https://github.com/jsvazic/hibernate-search-example
Any help would be greatly appreciated.
source to share
Your problem is not with the annotation @Transient
inside Foo,
, but before Foo
in general. Some code inside the indexing routine tries to call Session.lock(foo),
while Foo
still being a simple object, before assigning a session with Session.save
or Session.persist
. Perhaps this would help to add a parameter cascade=PERSIST
to annotation on a field Foo
in the parent as described here .
source to share