Bonjour, je tente actuellement d'executer une requete sur une table avec une clé primaire composée mais le soucis c'est qu'il ne semble pas reconnaitre cette clé :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
could not resolve property: IdProfil of: fr.annu.hibernate.ApplicationProfil [ from fr.annu.hibernate.Profil p where p.id in ( select ap.IdProfil from fr.annu.hibernate.ApplicationProfil ap where ap.IdApplication =3 group by ap.IdProfil )]

Voici le mapping des classes en question :

mapping classe ApplicationProfil, avec clé composite:
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
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
 
<hibernate-mapping package="fr.annu.hibernate">
	<class name="ApplicationProfil" table="APPLI_PROFIL">
		<composite-id name="id" class="fr.annu.hibernate.compositeKeys.ApplicationProfilCompositePK" unsaved-value="any" >
			<key-many-to-one
				name="IdApplication"
				class = "Application"
				column="ID_APPLICATION" 
				lazy="false"
			/>
			<key-many-to-one
				name="IdProfil"
				class = "Profil" 
				column="ID_PROFIL"
				lazy="false"
			/>
		</composite-id>
		<property
			column="COMMENTAIRE"
			length="30"
			name="commentaire"
			type="string"
		 />
	</class>
</hibernate-mapping>
classe de la clé composite:
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
package fr.annu.hibernate.compositeKeys;
 
import java.io.Serializable;
import java.math.BigDecimal;
 
public class ApplicationProfilCompositePK implements Serializable {
  private BigDecimal idApplication;
  private BigDecimal idProfil;
 
  public BigDecimal getIdApplication() {
    return idApplication;
  }
  public void setIdApplication(BigDecimal idApplication) {
    this.idApplication = idApplication;
  }
  public BigDecimal getIdProfil() {
    return idProfil;
  }
  public void setIdProfil(BigDecimal idProfil) {
    this.idProfil = idProfil;
  }
 
 
  @Override
  public boolean equals(Object obj) {
    boolean isEquals = false;
    ApplicationProfilCompositePK other = (ApplicationProfilCompositePK)obj;
    isEquals = this.getIdApplication().equals(other.getIdApplication());
    isEquals = isEquals && this.getIdProfil().equals(other.getIdProfil());
    return isEquals;
  }
 
  @Override
  public int hashCode() {
    return super.hashCode();
  }
 
}
mapping classe Profil:
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
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
 
<hibernate-mapping package="fr.annu.hibernate">
	<class name="Profil" table="PROFIL">
		<id
			column="ID_PROFIL"
			name="id"
			type="java.math.BigDecimal"
		>
		</id>
 
		<property
			column="CD_PROFIL"
			length="4"
			name="codeProfil"
			type="string"
		 />
		<property
			column="LIBELLE_PROFIL"
			length="20"
			name="libelleProfil"
			not-null="true"
			type="string"
		 />
 
	</class>
</hibernate-mapping>
méthode contenant la requete:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
	public static List getProfilList(BigDecimal id){
		Session session = HibernateUtil.currentSession();
		List profils = null;
		String maRequete = " from Profil p where p.id in ( select ap.IdProfil from ApplicationProfil ap where ap.IdApplication ="+id+" group by ap.IdProfil )";
		try{
			profils = ProfilDAO.getInstance().find(maRequete);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return profils;
	}

J'avouerais que c'est la premiere fois que je touche à une classe avec un clé composite donc je galerere un peu mais bon :d


Si vous pouviez me filer un petit coup de main



Merci.