In some very specific cases (no lifecycle callbacks, no cascades, …), deleting an entity could only involve running a few DB statements along the lines of delete from table where id = ?. In those cases, loading the entity would (in theory) not be necessary. In those very specific cases, when EntityManager.delete(Object) gets passed an uninitialized entity proxy, it would be a nice optimization if Hibernate ORM could skip initializing the proxy and just run the delete statements. This would remove at least one DB lookup for users doing a “delete-by-id” such as session.delete(session.getReference(MyEntity.class, 42L)) in some situations, while still doing the right thing (cascades, calling listeners, …) when the optimization is not possible. Note I’m not sure this is possible, but it’s probably worth investigating, be it only to document why it’s not possible. Related discussions:
|