vladmihalcea / hypersistence-optimizer

Hypersistence Optimizer allows you to get the most out of JPA and Hibernate. By scanning your application configuration and mappings, Hypersistence Optimizer can tell you what changes you need to do to speed up your data access layer.
https://vladmihalcea.com/hypersistence-optimizer/
Apache License 2.0
315 stars 43 forks source link

Prevent the BidirectionalSynchronizationEvent from triggering for immutable collections #141

Closed vladmihalcea closed 3 years ago

vladmihalcea commented 3 years ago

If the bidirectional collection association is annotated with the @Immutable annotation, then the BidirectionalSynchronizationEvent should not be triggered since the collection won't ever modify.

henke77 commented 3 years ago

Hi @vladmihalcea, there ist a similar issue regarding the rule MAJOR - The [...] element-collection in the [...] entity requires all child operations to be executed from the parent side, hence, if you want to add or remove a child element, you always need to fetch the collection. Consider using a bidirectional one-to-many association instead which allows you to operate on the @ManyToOne side without having to fetch the collection in the parent entity.

Also here we have marked the relation as @Immutable - and thus would not expect the event to be triggered.

vladmihalcea commented 3 years ago

Makes sense. Thanks for the tip

vladmihalcea commented 3 years ago

Fixed.