Hello. I don' undestand how is it possible to do.
Please, see my code:

@Entity
@Table(name = "Person", schema = SCHEMA)
 
public class Person {
 
        @Id
        @GeneratedValue
        @Column(name = "id")
        private int id;
 
        private String medialogyUid;
        private String firstName;
        private String lastName;
        private String patronymic;
        private String biography;
}
 
 
@Entity
@IdClass(Convocation.PK.class)
@Table(name = "Convocation", schema = SCHEMA)
 
public class Convocation {
 
        @Id
        private int number;
        
        @Id
        @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE,
CascadeType.REFRESH, CascadeType.PERSIST})
        private Institution institution;
        
        private Date beginDate;
        private Date endDate;
        
        public Convocation(){
                
        }
        
        public Convocation(Institution inst, int number, Date beginDate, Date
endDate){
                this.institution = inst;
                this.number = number;
                this.beginDate = beginDate;
                this.endDate = endDate;
        }
        
        public static final class PK implements Serializable {
 
                public int number;
                public int institution;
                
                public PK(){
                        
                }
                /[EMAIL PROTECTED] number is convocation,number
                 * @param institution is convocation.institution.id
                 * */
                public PK(int number, int institution){
                        this.number = number;
                        this.institution = institution;
                }
                
                @Override
                public boolean equals(Object o) {
                        if (!(o instanceof PK))
                                return false;
                        PK oPK = (PK)o;
                        return this.number == oPK.number && this.institution  
== oPK.institution;
                }
 
                @Override
                public int hashCode() {
                        return ((number == 0) ? 0 : new 
Integer(number).hashCode()) ^
((institution == 0) ? 0 : new Integer(institution).hashCode());
                }
    }
 
//And finally the last class:
 
@Entity
@IdClass(DeputyMandate.PK.class)
@Table(name = "DeputyMandate", schema = SCHEMA)
public class DeputyMandate {
        
        @Id
    @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE,
CascadeType.REFRESH, CascadeType.PERSIST})
        private Person person;
 
        @Id
        @ManyToOne(fetch=FetchType.EAGER, cascade={CascadeType.MERGE,
CascadeType.REFRESH, CascadeType.PERSIST})
        private Convocation convocation;
        
        private Date dateIn;
        private Date dateOut;
        
        public static final class PK implements Serializable {
               //don't know what to use @Embeddable or what?
        }
    }



I want DeputyMandate to use composite key. This composite key is based on
Person with simple key (int id) and Convocation PK.
Please, tell me how can I make composite key DeputyMandate.PK using simple
key from Person and composite key from Convocation.
-- 
View this message in context: 
http://n2.nabble.com/Enterprise-JavaBeans---HowTo%3A-construct-Composite-key-using-other-composite-key--tp788926p788926.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to