Bonjour à tous,
J'essaye en vain de mapper une clé primaire composée contenant à la fois un "int" et une entité.
J'ai 2 entités : SystemSelection correspond à un SystemInfo et à un id de Plan (cf. Schema bdd en PJ). Je souhaite sélectionner un SystemSelection à partir de l'id du SystemInfo.
Voici ma classe SystemSelectionPuis ma classe SystemInfo :
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 @Entity @Table(name="systemSelection") @IdClass(SystemSelectionKey.class) public class SystemSelection implements Serializable { /** * The generated serial version id */ private static final long serialVersionUID = -5714390642967962267L; @Id @Column(name="plan_id") private int planId = 0; @Id @ManyToOne @JoinColumn(name="system_id") private SystemInfo systemInfo = null; @Column(name="is_visible") private boolean isVisible = true; //... }Et enfin ma classe SystemSelectionKey :
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 @Entity @Table(name="systemInfo") @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public class SystemInfo { /** * */ private static final long serialVersionUID = -2606211766798365116L; @Id @Column @GeneratedValue(strategy=GenerationType.AUTO) private int id = 0; @Column private String name = ""; @Column private String description = ""; @Column(name="planmanager_id") private Integer planManagerId = 0; //... }La "compilation" semble bien se dérouler, mais lorsque je fais ma requête la trace est bizarre :
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 @Embeddable public class SystemSelectionKey implements Serializable { /** * */ private static final long serialVersionUID = -7081405104395508365L; private SystemInfo systemInfo = null; private int planId = 0; public int getPlanId() { return planId; } public SystemInfo getSystem() { return systemInfo; } public void setPlanId(int planId) { this.planId = planId; } public void setSystem(SystemInfo system) { this.systemInfo = system; } /* (non-Javadoc) * @see java.lang.Object#hashCode() */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + planId; result = prime * result + ((systemInfo == null) ? 0 : systemInfo.hashCode()); return result; } /* (non-Javadoc) * @see java.lang.Object#equals(java.lang.Object) */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SystemSelectionKey other = (SystemSelectionKey) obj; if (planId != other.planId) return false; if (systemInfo == null) { if (other.systemInfo != null) return false; } else if (!systemInfo.equals(other.systemInfo)) return false; return true; } }Cette requête provoque sans grande surprise l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 select <liste_des_champs> from system this_ inner join systemInfo systeminfo3_ on this_.system_id=systeminfo3_.id where systeminfo1_.id=?Sans grande surprise puisque l'alias "systeminfo1_" n'est pas définit dans la requête.Champ 'systeminfo1_.id' inconnu dans where clause
Voici ma méthode DAO (j'utilise Spring et HibernateDaoSupport) :Une idée d'où vient le problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 public SystemSelection selectSystemSelection(int id) { DetachedCriteria criteria = DetachedCriteria.forClass(SystemSelection.class) .createAlias("systemInfo", "systemInfo") .add(Restrictions.eq("systemInfo.id", id)) .setResultTransformer(DetachedCriteria.DISTINCT_ROOT_ENTITY); return DataAccessUtils.singleResult(getHibernateTemplate().findByCriteria(criteria)); }
Partager