KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > manytoone > ParentPk


1 //$Id: ParentPk.java,v 1.1 2005/05/12 13:33:33 epbernard Exp $
2
package org.hibernate.test.annotations.manytoone;
3
4 import javax.persistence.AccessType;
5 import javax.persistence.Column;
6 import javax.persistence.Embeddable;
7 import java.io.Serializable JavaDoc;
8
9 /**
10  * @author Emmanuel Bernard
11  */

12 @Embeddable(access = AccessType.FIELD)
13 public class ParentPk implements Serializable JavaDoc {
14     @Column(length=50)
15     String JavaDoc firstName;
16     String JavaDoc lastName;
17
18     /** is a male or a female */
19     //show hetereogenous PK types
20
boolean isMale;
21
22     public int hashCode() {
23         //this implem sucks
24
return firstName.hashCode() + lastName.hashCode() + (isMale?0:1);
25     }
26
27     public boolean equals(Object JavaDoc obj) {
28         //firstName and lastName are expected to be set in this implem
29
if (obj != null && obj instanceof ParentPk) {
30             ParentPk other = (ParentPk) obj;
31             return firstName.equals(other.firstName)
32                     && lastName.equals(other.lastName)
33                     && isMale == other.isMale;
34         }
35         else {
36             return false;
37         }
38     }
39 }
40
Popular Tags