Bonjour,

J'ai un petit soucis avec mon mapping. Lorsque je fais la requête de sélection de mon entité A, il me renvoie une liste de mon entité B vide. Pourtant la requête est bien envoyée coté base de donnée.

Mon mapping.

Entité Motor :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
@Entity
@Table(name = "Motor")
public class Motor extends RefObject {
    private static final long serialVersionUID = -8759210425878668688L;
 
@ManyToMany(fetch=FetchType.LAZY)
    @Cascade(CascadeType.ALL)
    @JoinTable(name = "Study_Motor", joinColumns = @JoinColumn(name="id_motor", referencedColumnName = "id"),
    								 inverseJoinColumns = @JoinColumn(name="id_study", referencedColumnName = "id"))
    private List<Study> studyList;
 
...
Entité Study :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
@Entity
@Table(name = "Study")
public class Study extends RefObject {
    private static final long serialVersionUID = 6983982151873860807L;
 
@ManyToMany(mappedBy = "studyList", fetch = FetchType.LAZY)
    private List<Motor> motorList;
 
...
Je voudrais donc récupérer la liste des Motor associé a une Study. J'ai testé avec hql et criteria sans succès.

avec Criteria :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
Criteria criteria = currentSession.createCriteria(Study.class);
		criteria.add(Restrictions.eq("id", study.getId()));
		criteria.setFetchMode("application", FetchMode.JOIN);
                criteria.setFetchMode("motorList", FetchMode.JOIN)
en hql :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
Query query = currentSession.createQuery("from Study s left join fetch s.application a"
				+ " left join fetch s.motorList m"
				+ " where s.id = :id");
		query.setParameter("id", study.getId());
La requête sql générée me parait correcte, les jointures sont faites correctement (Motor, Motor_Study, Study) :

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
Hibernate: 
    select
        study0_.id as id1_50_0_,
        applicatio1_.id as id1_0_1_,
        motor3_.id as id1_25_2_,
        study0_.reference as referenc2_50_0_,
        study0_.creationDate as creation3_50_0_,
        study0_.creator as creator4_50_0_,
        study0_.application as applicat5_50_0_,
        study0_.gate as gate6_50_0_,
        applicatio1_.reference as referenc2_0_1_,
        applicatio1_.creationDate as creation3_0_1_,
        applicatio1_.creator as creator8_0_1_,
        applicatio1_.applicationType as applicat9_0_1_,
        applicatio1_.customer as custome10_0_1_,
        applicatio1_.cylinder as cylinder4_0_1_,
        applicatio1_.description as descript5_0_1_,
        applicatio1_.fluid as fluid11_0_1_,
        applicatio1_.keyLaboTE as keyLaboT6_0_1_,
        applicatio1_.operation as operatio7_0_1_,
        applicatio1_.pressure as pressur12_0_1_,
        applicatio1_.specification as specifi13_0_1_,
        applicatio1_.technicalInstruction as technic14_0_1_,
        applicatio1_.ventilation as ventila15_0_1_,
        motor3_.reference as referenc2_25_2_,
        motor3_.creationDate as creation3_25_2_,
        motor3_.creator as creator13_25_2_,
        motor3_.maxiCapacitorStart as maxiCapa4_25_2_,
        motor3_.mechanicalLosses as mechanic5_25_2_,
        motor3_.mechanicalLossesInitialization as mechanic6_25_2_,
        motor3_.miniCapacitorStart as miniCapa7_25_2_,
        motor3_.parallelPTCResistor as parallel8_25_2_,
        motor3_.permanentCapacitor as permanen9_25_2_,
        motor3_.prototypeReference as prototy10_25_2_,
        motor3_.rotor as rotor14_25_2_,
        motor3_.serialPTCResistor as serialP11_25_2_,
        motor3_.serialReference as serialR12_25_2_,
        motor3_.stator as stator15_25_2_,
        motor3_.voltage1 as voltage16_25_2_,
        motor3_.voltage2 as voltage17_25_2_,
        motorlist2_.id_study as id_study2_50_0__,
        motorlist2_.id_motor as id_motor1_52_0__ 
    from
        Study study0_ 
    left outer join
        Application applicatio1_ 
            on study0_.application=applicatio1_.id 
    left outer join
        Study_Motor motorlist2_ 
            on study0_.id=motorlist2_.id_study 
    left outer join
        Motor motor3_ 
            on motorlist2_.id_motor=motor3_.id 
    where
        study0_.id=?

Ma liste de motor reste vide, si vous pouviez me donner une idée ce serai cool !
Merci