KickJava   Java API By Example, From Geeks To Geeks.

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


1 //$Id: ParentPk.java,v 1.2 2005/06/23 14:10:57 epbernard Exp $
2
package org.hibernate.test.annotations.onetomany;
3
4 import java.io.Serializable JavaDoc;
5 import javax.persistence.AccessType;
6 import javax.persistence.Embeddable;
7
8 /**
9  * @author Emmanuel Bernard
10  */

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