In some cases the SearchIndexingPlan generate a ConcurrentModificiationException if an embedded entities is not listed in the *addOrUpdate* or on specific order (if only the *last* entity is concern this case)
{noformat}SearchSession searchSession = Search.session((EntityManager) sessionFactory.getCurrentSession()); SearchIndexingPlan searchWritePlan = searchSession.indexingPlan(); // this order endup to the exception below searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class), 12445l)); searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class, 12444l)); searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class, 12443l)); // this order is fine searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class), 12443l)); searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class, 12444l)); searchWritePlan.addOrUpdate(rootRepository.load(ClientPhysique.class, 12445l)); searchWritePlan.process(); searchWritePlan.execute(); {noformat}
Explanation from *@**yrodiere* *:*
The problem is probably in {{ org.hibernate.search.mapper.pojo.work.impl.PojoIndexingPlanImpl#process }} , in this loop:
{noformat} for ( PojoIndexedTypeIndexingPlan<?, ?, ?> delegate : indexedTypeDelegates.values() ) { delegate.resolveDirty( this::updateBecauseOfContained ); } {noformat}
The call to {{ resolveDirty }} will trigger a loop on {{ indexingPlansPerId }} that executes an operation of each element of that map. The problem is, this operation might trigger the addition of an element to the map {{ indexedTypeDelegates }} (through {{ org.hibernate.search.mapper.pojo.work.impl.PojoIndexingPlanImpl#getOrCreateIndexedDelegateForContainedUpdate }} ), or to the map {{ indexingPlansPerId }} (through {{ org.hibernate.search.mapper.pojo.work.impl.PojoIndexedTypeIndexingPlan#getPlan }} ), when we discover a type/entity that wasn’t present in the map initially.
The concurrent modification is not a problem _per se_, because we don’t need to call {{ resolveDirty }} on newly added elements. However, it’s a problem because the iterator will detect the concurrent modification and throw an exception.
see [https://discourse.hibernate.org/t/searchindexingplan-exception-when-using-addorupdate-in-different-order/3846|https://discourse.hibernate.org/t/searchindexingplan-exception-when-using-addorupdate-in-different-order/3846]
|
|