I'm using Hibernate with JTA (container managed transactions).
Let's say I have the following model: Employee with many-to-one relations to Office and Team. I've set up bidirectional associations.
class Employee{
Office office;
Team team;
}
class Office{
List<Employee> employees;
}
class Team{
List<Employee> employees;
}
Now the data:
Emp 1 with Ofc 1 and Team 1
Emp 2 with Ofc 1 and Team 2
The problem: I iterate over the Team 1 employees (i.e. just emp 1) and delete them. Then within the same transaction I execute HQL select to get Ofc 1. Now within Ofc 1 employees list I expect to find just emp 2 (since emp 1 has been deleted on the previous step) but the result is that both employees are still there.
I tried flushing the entity manager after the deletion: same thing.