When Hibernate is used with JPA it inspects @Immutable entity during flushing.
Steps to reproduce
1. Configure persistence.xml
2. Configure @Immutable entity
3. Configure log4j.logger.org.hibernate=TRACE
4. Load @Immutable entity from DB
5. Perform flush or commit transaction
Result is visible in log
This creates performance degradation especially if @Immutable entity has @Immutable @OneToMany collection and Processing flush-time cascades occurs for every element.
How to map an immutable entity with JPA and Hibernate says The reason why Hibernate does not track @Immutabale entity modifications is because the entity is loaded in read-only mode, hence the detachedState or hydratedState is never stored in the currently running Persistence Context.
Issue might be related to HHH-4993
Issue exists on 5.3 and 5.4.8.Final
Issue does not happen with plain Hibernate because of code
I attached example where problem is visible.