framework-web:spring:relations

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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] jcheronframework-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'usage : Un auteur a plusieurs livres, un livre a un seul auteur. Cas d'usage : Un auteur a plusieurs livres, un livre a un seul auteur.
  
-=== 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 = "author" // ❌ N'est PAS le owner+    @OneToMany(mappedBy = "author" // ❌ Non owner
     private List<Book> books;     private List<Book> books;
 } }
Ligne 536: Ligne 536:
 public class Book { public class Book {
     @ManyToOne     @ManyToOne
-    @JoinColumn(name = "author_id" // ✅ EST le owner+    @JoinColumn(name = "author_id" // ✅ Owner
     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,  -- ← LA CLÉ ÉTRANGÈRE EST ICI !+    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:
  
 ''application.properties'' : ''application.properties'' :
-<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>
  
  
  • framework-web/spring/relations.1759878001.txt.gz
  • Dernière modification : il y a 2 mois
  • de jcheron