2015-03-16 1 views

Répondre

1

Voici l'exemple de la documentation

public class EmployeePK implements Serializable { 

    private long empId; 
    private long department; 

    public EmployeePK() { 
    } 

    public long getEmpId() { 
     return this.empId; 
    } 

    public void setEmpId(long empId) { 
     this.empId = empId; 
    } 

    public long getDepartment() { 
     return this.department; 
    } 

    public void setDepartment(long department) { 
     this.department = department; 
    } 

    public int hashCode() { 
     return (int)this.empId.hashCode(); 
    } 

    public boolean equals(Object obj) { 
     if (obj == this) return true; 
     if (!(obj instanceof EmployeePK)) return false; 
     EmployeePK pk = (EmployeePK) obj; 
     return pk.empId.equals(this.empId) && pk.department.equals(this.department); 
    } 
} 

et

@IdClass(EmployeePK.class) 
@Entity 
public class Employee implements Serializable{ 

    @Id 
    long empId; 
    @Id 
    @ManyToOne 
    Department department; 
    ... 
}