I am in the process of migrating an application from Hibernate 4.3 to Hibernate 6.2. In several cases, one Hibernate session is opened for each request done on the server. However, the request may chain multiple transactions which share the same Hibernate session. This has never been an issue in the past, but now it is causing TransientObjectException errors. I have been able to isolate the following case. Imagine having students and courses and a table/entity mapping enrollments of students to courses containing additional fields like timestamp, grade, etc. Student entity:
Course entity:
Enrollment entity (many-to-many relation between courses and students):
Now, imagine that a student and two courses already exist, and we want to enroll the student into the two courses like this. And in the following transaction credit information of one of the two courses is updated:
The course lookup in the second transaction (like 29) fails with the following exception:
The problem does not occur when
- the student is being created together with the new enrollment records (i.e. when calling hibSession1.persist(s1))
- when each enrollment is persisted before merging the student
- a new session is opened for the second transaction
Is this behavior intentional? This has not been an issue in the past using Hibernate 3 or 4. See the attached files for the whole test. |