Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| framework-web:spring:relations [2025/10/08 01:00] – [Problème N+1] jcheron | framework-web:spring:relations [2025/10/08 01:24] (Version actuelle) – [Schéma de base de données] jcheron | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| ====== Relations JPA ====== | ====== Relations JPA ====== | ||
| - | ===== Les Types de Relations ===== | + | ===== Types de Relations ===== |
| ==== @OneToMany / @ManyToOne ==== | ==== @OneToMany / @ManyToOne ==== | ||
| Ligne 7: | Ligne 7: | ||
| Cas d' | Cas d' | ||
| - | === Configuration Unidirectionnelle (❌ Rarement recommandée) === | + | === Configuration Unidirectionnelle (🟰 Rarement recommandée) === |
| <sxh java> | <sxh java> | ||
| @Entity | @Entity | ||
| Ligne 529: | Ligne 529: | ||
| @Entity | @Entity | ||
| public class Author { | public class Author { | ||
| - | @OneToMany(mappedBy = " | + | @OneToMany(mappedBy = " |
| private List< | private List< | ||
| } | } | ||
| Ligne 536: | Ligne 536: | ||
| public class Book { | public class Book { | ||
| @ManyToOne | @ManyToOne | ||
| - | @JoinColumn(name = " | + | @JoinColumn(name = " |
| private Author author; | private Author author; | ||
| } | } | ||
| Ligne 551: | Ligne 551: | ||
| id BIGINT PRIMARY KEY, | id BIGINT PRIMARY KEY, | ||
| title VARCHAR(255), | title VARCHAR(255), | ||
| - | author_id BIGINT, | + | author_id BIGINT, |
| CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES author(id) | CONSTRAINT fk_author FOREIGN KEY (author_id) REFERENCES author(id) | ||
| ); | ); | ||
| Ligne 1013: | Ligne 1013: | ||
| '' | '' | ||
| - | <code> | + | <sxh bash> |
| # Afficher les requêtes SQL | # Afficher les requêtes SQL | ||
| spring.jpa.show-sql=true | spring.jpa.show-sql=true | ||
| Ligne 1023: | Ligne 1023: | ||
| # Détecter le problème N+1 | # Détecter le problème N+1 | ||
| spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=10 | spring.jpa.properties.hibernate.session.events.log.LOG_QUERIES_SLOWER_THAN_MS=10 | ||
| - | </code> | + | </sxh> |