I have a Spring integrated test that is wrapped in @Transactional
. The Hibernate/JPA database interface extends JpaRepository
and uses PESSIMISTIC_READ
and PESSIMISTIC_WRITE
locks on its functions. Within the test, the following steps occur:
- An
@Entity
object is read from the repo. - The target function runs, which updates and writes that same
@Entity
to the repo inside another@Service
-level transaction. - That
@Entity
object is again read from the repo and compared to the first object.
The problem is that after writing in step 2, the first @Entity
object has actually been updated locally. When comparing the @Entity
objects in step 3, both are equal instead of having expected "before and after" differences.
How is this "syncing" of local @Entity
objects happening, and is this expected behavior?