Hibernate search 6: random error with Type bridge

52 views Asked by At

in a Spring boot 3 project, I am using Hibernate search 6.1.8Final for data indexing in an Elasticserach backend. I added a typeBinder bridge to index a calculated value. In the calculation method I make a select on the database with a JPARepository. I encountered an exception a few times when modifying the object but after that the error disappeared and I don't know if it will be random. Knowing that the exception is not blocking for persistence in the database and updating the index. exception text: org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction] with root cause org.hibernate.search.util.common.SearchException: HSEARCH700060: Unable to trigger entity processing while already processing entities. Make sure you do not change entities within an entity getter or a custom bridge used for indexing, and avoid any event that could trigger entity processing. Hibernate ORM flushes, in particular, must be avoided in entity getters and bridges.

In fact, after updating an indexed object, on-going reindexing is launched. the exception is triggered when the Bridge is called and more precisely when the repository is called. I would like to understand the cause of this error but I have found almost nothing on the subject.

Thanks for your help.

2

There are 2 answers

0
Linda BO On BEST ANSWER

Thank you very much for your answer.
I found the solution, by looking more closely in the hibernate search calls. In fact, my call to the repository (which is a simple find with no action on the database) in my bridge calls a native query and there I have the execution of the flush. By changing to an HQL query, there is no longer a problem. I think that the fact that the request is native and that hibernate serach will be in this way it does not know what it does, it automatically launches a flush. When I go to an HQL query, it has the commands and it knows that it's just a get so it doesn't do a flush? On the other hand, what I found strange was that at a given moment the error was random.
Thank you.

3
yrodiere On

The exception is telling you what's wrong:

Hibernate ORM flushes, in particular, must be avoided in entity getters and bridges.

Hard to say without a reproducer, but my guess it that this is happening:

You didn't provide your mapping/bridge code, or even a stacktrace, so I can't really tell you how to fix your problem.

Here are some guesses as to why the second flush even happens (why would it, since Hibernate ORM already triggered one?):

  • An obvious problem would be if you call a setter in your bridge, but you don't do that, right? That wouldn't make sense.
  • Perhaps your mapping is using some user types that prevent Hibernate ORM from determining that a flush is necessary, and as a result Hibernate ORM always flushes?
  • Perhaps running queries within bridges just doesn't work. We have a test for that, but honestly it's very basic. I couldn't find a feature request for what you're doing; https://hibernate.atlassian.net/browse/HSEARCH-1937 is close but it's about using a query to retrieve indexing dependencies, so probably not what you're after.