1 package org.hibernate.test.annotations.onetomany; 3 4 import java.io.Serializable ; 5 import java.util.HashSet ; 6 import java.util.Set ; 7 import javax.persistence.AccessType; 8 import javax.persistence.CascadeType; 9 import javax.persistence.Entity; 10 import javax.persistence.Id; 11 import javax.persistence.OneToMany; 12 13 import org.hibernate.annotations.BatchSize; 14 15 18 @Entity(access = AccessType.FIELD) 19 public class Parent implements Serializable { 20 @Id 21 public ParentPk id; 22 public int age; 23 24 @OneToMany(cascade=CascadeType.ALL, mappedBy="parent") 25 @BatchSize(size=5) 26 @javax.persistence.OrderBy("favoriteSuperhero asc, favoriteSinger desc") 27 public Set <Child> children; 28 29 public int hashCode() { 30 return id.hashCode(); 32 } 33 34 public boolean equals(Object obj) { 35 if (obj != null && obj instanceof Parent) { 37 return id.equals( ( (Parent) obj).id ); 38 } 39 else { 40 return false; 41 } 42 } 43 44 public void addChild(Child child) { 45 if (children == null) { 46 children = new HashSet (); 47 } 48 child.parent = this; 49 children.add(child); 50 } 51 } 52 | Popular Tags |