It seems that the Hibernate EntityManager find method behaves differently in the following two cases:
Case 1 – Entity does not exist in the database before transaction starts. Within transaction, find of the entity returns null.
Case 2 – Entity exists in DB before transaction. Within transaction, entity is remove‘d, then a find of the same key throws EntityNotFoundException.
Is this expected behaviour? Do I need to do a flush before the find for it to behave the same?
It is unexpected that
findmethod inEntityManagerthrowsEntityNotFoundExceptionwhen entity is not found. Documentation is quite clear:This bug was reported in HHH-7861. It is fixed in 4.1.10, which is not yet released.