After deleting an entity lucene index updating fails due to NullPointerException


When entities are deleted, I noticed an exception with a rather large stack trace (below), which appears to be caused by the fact that Lucene is told to remove from the index a document with a null id.

After (quite) a bit of digging, I believe the source is the top of this stack trace:

Specifically, does:

As far as I can tell, unproxy(entity) will return an entity with a null id if called during postRemove; the returned result is null, although the debugger says that actually contains the correct (non-null, pre-deletion) value.<T>), right below the top of the stack, does:

This condition fails and goes into the "else" block, which is unfortunate, because work.getId() actually contains the correct value.

The error doesn't occur right away:<T>) (a bit below the top of the stack) calls "entityById.put( id, entityWork );", with id=null due to the above.

A while later the following happens (the bottom two items are the same as the stack trace above):

The entry at the top belongs to

The argument delete is true and id is null (it's the value of WorkPlan$PerClassWork<T>.enqueueLuceneWork(List<LuceneWork>) gets it from the documentBuilder.getId(entity) call mentioned above). A little while later the actual exception is triggered:

org.apache.lucene.index.Term.compareTo fails because is null, having received its value a bit earlier from the null document id above. (Technically, I think this also a bug in lucene; surrounding code, for example Term.equals, does test for null, so either Term.compareTo should do it, or the Term should have been checked for null quite a while earlier. Anyway, the results would have been the same, except for easier debugging.)


Hibernate 3.4.0 (on MySQL 5.1.54, but any database is affected AFAIK)


Hardy Ferentschik


Bogdan Butnaru



Suitable for new contributors

Yes, likely

Pull Request


Feedback Requested



Affects versions