//$Id: Parent.java,v 1.3 2005/02/13 22:46:18 epbernard Exp $ package org.hibernate.test.metadata.onetomany; import org.hibernate.annotations.BatchSize; import javax.ejb.Entity; import javax.ejb.AccessType; import javax.ejb.Id; import javax.ejb.OneToMany; import javax.ejb.CascadeType; import javax.ejb.JoinColumns; import javax.ejb.JoinColumn; import java.util.Collection; import java.util.Set; import java.util.HashSet; import java.io.Serializable; /** * @author Emmanuel Bernard */ @Entity(access = AccessType.FIELD) public class Parent implements Serializable { @Id public ParentPk id; public int age; @OneToMany(cascade=CascadeType.ALL) @JoinColumns ({ @JoinColumn(name="parentCivility", referencedColumnName = "isMale"), @JoinColumn(name="parentLastName", referencedColumnName = "lastName"), @JoinColumn(name="parentFirstName", referencedColumnName = "firstName") }) @BatchSize(size=5) public Set children; public int hashCode() { //a NPE can occurs, but I don't expect hashcode to be used before pk is set return id.hashCode(); } public boolean equals(Object obj) { //a NPE can occurs, but I don't expect equals to be used before pk is set if (obj != null && obj instanceof Parent) { return id.equals( ( (Parent) obj).id ); } else { return false; } } public void addChild(Child child) { if (children == null) { children = new HashSet(); } child.parent = this; children.add(child); } }