// PK pour Primary Key import java.io.Serializable; import javax.persistence.Embeddable; // Pour que la classe puisse être intégré dans Personne // sans passer par une autre table @Embeddable // La classe doit implémenter Serializable public class PersonnePK implements Serializable { // Les champs privés qui serviront d'Id multiple. private String nom; private String prenom; // Les getter et les setter public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } // hashCode et equals : généré automatiquement depuis Eclipse. @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((nom == null) ? 0 : nom.hashCode()); result = prime * result + ((prenom == null) ? 0 : prenom.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; PersonnePK other = (PersonnePK) obj; if (nom == null) { if (other.nom != null) return false; } else if (!nom.equals(other.nom)) return false; if (prenom == null) { if (other.prenom != null) return false; } else if (!prenom.equals(other.prenom)) return false; return true; } }