Hibernate tries to flush @Immutable entity
Description
Attachments
1
Activity
Show:

Jörg Liebig June 15, 2020 at 7:43 AM
Hi,
I’m experiencing the same problem in Hibernate 5.4.17.Final. I’m trying to write a new entity that references via collection/relationship potentially thousands of immutable entities. Due to the flush the operation is quite slow, e.g., > 1000 ms for writing only 1 entity, that references in one scenario 6000 immutable entities. I tried to work around this issue, by trying to update the collection/relationship via JPQL/HQL query, which seems to be impossible according to https://en.wikibooks.org/wiki/Java_Persistence/JPQL#Update_Queries.
Is there anything I can do?
Best regards
Jörg Liebig
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.