Bonjour,

j'ai un petit souci. J'ai 2 tables dans ma base :

- une table chapitre : chap_id, chap_titre, ...

- une table choix (qui fait le lien entre les chapitres) : chap_origine (FK = chap_id), chap_suivant (FK = chap_id), choix_nom ==>(du lien)

L'idée : un chapitre peut diriger vers plusieurs autres chapitres (et vice versa), nous sommes donc bien dans une relation ManyToMany.

J'ai également une requête sql qui fonctionne (testée dans ma base)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
SELECT ch.* FROM choix ch WHERE ch.chap_origine = :idC
Cette requête me renvoie bien ce que je veux.

Maintenant c'est là que ça se complique.

J'ai ce model : Chapitre
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
@Entity
@Table(name = "chapitre")
public class Chapitre implements Serializable {
 
    @Id
    @Column(name = "chap_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
 
    @Column(name = "chap_titre")
    private String titre;
 
    @Column(name = "chap_type")
    private String type;
 
    //liaison avec livre
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "livre_id")
    private Livre livre;
 
    //Liaison modèlisée dans la table choix
    @ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
    @JoinTable(name = "choix",
     joinColumns = {@JoinColumn(name = "chap_origine", referencedColumnName = "chap_id")},
     inverseJoinColumns = {@JoinColumn(name = "chap_suivant", referencedColumnName = "chap_id")}
    )
    private List<Chapitre> choix;

Et j'ai ce repository : ChapitreRepository
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
 
//afficher les choix de chapitre suivant
    @Query(value = "SELECT ch.* FROM choix ch WHERE ch.chap_origine = :idC", nativeQuery = true)
    List<Chapitre> choixDesChapitresSuivant(@Param("idC") Integer idC);

Mais je n'arrive pas à récupérer les données.
J'ai voulu faire un truc tout bête pour récupérer le chap_suivant et choix_nom. Mais j'ai cette stack d'erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
!!!!!!TEST NAVIGATION : exemple avec chapitre 4!!!!!!
Hibernate: SELECT ch.* FROM choix ch WHERE ch.chap_origine = ?
2021-03-07 00:21:57.078  WARN 85704 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: S0022
2021-03-07 00:21:57.078 ERROR 85704 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column 'chap_id' not found.
2021-03-07 00:21:57.081  INFO 85704 --- [  restartedMain] ConditionEvaluationReportLoggingListener :
 
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-03-07 00:21:57.096 ERROR 85704 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed
 
java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:807) ~[spring-boot-2.4.1.jar:2.4.1]
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:788) ~[spring-boot-2.4.1.jar:2.4.1]
Je fais mes tests dans un runner actuellement, et je n'ai rien de plus que ça :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
System.out.println("!!!!!!TEST NAVIGATION : exemple avec chapitre 4!!!!!!");
        List<Chapitre> listeChoix = chapitreRepository.choixDesChapitresSuivant(4);
 
 
        for (Chapitre choix : listeChoix){
            print("Choix disponible = " + choix);
        }
Je ne comprends pas pourquoi il va chercher le chap_id dans le message :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
2021-03-07 00:21:57.078 ERROR 85704 --- [  restartedMain] o.h.engine.jdbc.spi.SqlExceptionHelper   : Column 'chap_id' not found.
Ce n'est pas ce que je lui demande.

Alors est-ce que c'est un problème de requête ou de mapping ?

Merci d'avance pour vos explications et votre aide