Spring's @EntityGraph mark my entities as dirty


I encounter some problem when I try to use org.springframework.data.jpa.repository.EntityGraph to improve performance to fetch my relations.
To do it I’m using the annotation on my repository methods:

@EntityGraph(attributePaths = {"relation"})

I noticed that every time I fetch a relation this way, my parent entities become dirty.

It’s actually problematic in my case since I have a PostCommitUpdateEventListener who catch this as an update and start some unintended logic.

When I watch the PostUpdateEvent’s state and oldState the difference is that every relations are all a LazyPropertyInitializer in the oldState while they are filled in the state with PersistentSet.

It looks like a classic use case and I feel like I’m missing something obvious.

For context I’m using:
hibernate-entitymanager 5.5.8.Final
hibernate-enhance-maven-plugin with enableLazyInitialization to true 5.5.8.Final
spring-boot-starter-parent 2.7.18

Hi there. Please note that at this point, bug fixes for the community are only done on the latest Hibernate ORM versions i.e. 6.4 and soon 6.5. Even if there still is a problem in the latest versions, we would not backport the fix.

So if you care about this, please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

It seems the problem is tied to bytecode enhancement, since if I set enableLazyInitialization to false nothing is dirty anymore.
But I want to keep BCE in place to not fetch eagerly my OneToOne relationships.

So I finally tried to also set enableDirtyTracking to true of the hibernate-enhance-maven-plugin and now it’s working as intended.