Criteria
https://www.devmedia.com.br/hibernate-api-criteria-realizando-consultas/29627
https://thoughts-on-java.org/common-hibernate-mistakes-cripple-performance/
Default relationship
OneToMany: LAZY ManyToOne: EAGER ManyToMany: LAZY OneToOne: EAGER
The latest version of Hibernate aligns with the above JPA defaults.
@ManyToMany
Join table
A table provides a mapping between two tables. It has foreign keys for each table to define the mapping relationship.
Cascade
You can cascade operatinos
Apply the same operation to related entities.
Cascade Delete
Instrutor 1-1 Hobby - se excluir o instrutor, delete o hobby
Cursos N-N Estudantes - se excluir o estudante, nao exclua os cursos, nao aplica cascade delete aqui.
Entity lifecycle
Detach - If entity is detached, it is not associates with a Hibernate session.
Merge - if instance is detached from session, then merge will reattach to session.
Persist - Transitions new instances to managed state. Next flush / commit will save in db.
Remove - Transitions managed entity to be removed. Next flush / commit will delete from db.
Refresh - Reload / synch object with data from db. Prevents stale data.