The goal of this gist is to apply Hibernate best practices for performance purposes:
- Use Bidirectional OneToMany relations, with Sets instead of Lists
- Transactions should be inside Services in order to combine several DAO calls inside the same transaction
- Using read-only transactions in order to describe when transactions should be readonly. Moreover, it improves performance and prevents non desired writes
- Mark read-only entities a @immutable
- Implement equals and hashcode with business key inside entities, which is useful especially for OneToMany relations
Interesting reads:
https://docs.jboss.org/hibernate/stable/core.old/reference/en/html/persistent-classes-equalshashcode.html https://vladmihalcea.com/hibernate-facts-equals-and-hashcode/ https://thoughts-on-java.org/best-practices-many-one-one-many-associations-mappings/ https://vladmihalcea.com/spring-read-only-transaction-hibernate-optimization/ https://vladmihalcea.com/hibernate-facts-favoring-sets-vs-bags/