Hibernate tries to force version increment on non-versioned entity


Test case contains simple gradle spring boot project with one junit test to demonstrate the bug. Read README.md, forgot to mention but add your database url and credentials to application.properties under test resources.
Test requires database. Tables and data can be found from data.sql under test resources.

Consider the following query, even though it has been implemented with spring jpa hibernate is the problem here.

Query says that every time station plan is fetched with id, increase version number optimistically at the end of transaction. Query also has @EntityGraph to join other entities in order to prevent n+1 problem. Hibernate will propagate OPTIMISTIC_FORCE_INCREMENT to station and station.stationTracks. First question is, should it propagate OPTIMISTIC_FORCE_INCREMENT for entities in EntityGraph's attributePaths?

Second question if it should propagate, should it propagate only to entities that are versionable? Station is versionable but station track is not. Hibernate will create EntityIncrementVersionProcess action for station track and at the end of transaction save will fail.






Jukka Lehtimäki