| The only way to improve on the pull request would be for Hibernate to track those entities that are not found when a batch is executed. Unfortunately, that would cause an inconsistency when using batch fetching versus not using it. Here is an example using Employee#task, where:
- the corresponding Employee column has task ID set to 1;
- there is no Task entity with that ID.
doInHibernate(
this::sessionFactory, session -> {
Employee employee = session.get( Employee.class, "employee01" );
assertNull( employee.task );
doInHibernate(
this::sessionFactory, session1 -> {
Task task = new Task( 1 );
session.persist( task );
}
);
session.refresh( employee );
assertNotNull( employee.task );
}
);
A possible improvement would be to only track entities that were not found only while an operation is in progress. Unfortunately, that would be difficult to do until we have OperationContext functionality, but that won't be available until Hibernate 6.0 when
HHH-10478 Open is fixed. |