1 package org.hibernate.test.annotations.manytoone; 3 4 import javax.persistence.CascadeType; 5 import javax.persistence.Entity; 6 import javax.persistence.FetchType; 7 import javax.persistence.Id; 8 import javax.persistence.JoinColumn; 9 import javax.persistence.JoinColumns; 10 import javax.persistence.ManyToOne; 11 import java.io.Serializable ; 12 13 16 @Entity 17 public class Node implements Serializable { 18 19 private NodePk id; 20 private String description; 21 private Node parent; 22 23 public boolean equals(Object o) { 24 if (this == o) return true; 25 if (!(o instanceof Node)) return false; 26 27 final Node node = (Node) o; 28 29 if (!id.equals(node.id)) return false; 30 31 return true; 32 } 33 34 public int hashCode() { 35 return id.hashCode(); 36 } 37 38 @Id 39 public NodePk getId() { 40 return id; 41 } 42 43 public void setId(NodePk id) { 44 this.id = id; 45 } 46 47 public String getDescription() { 48 return description; 49 } 50 51 public void setDescription(String description) { 52 this.description = description; 53 } 54 55 @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) 56 @JoinColumns({ 57 @JoinColumn(name="parentName"), 58 @JoinColumn(name="parentLevel") 59 }) 60 public Node getParent() { 61 return parent; 62 } 63 64 public void setParent(Node parent) { 65 this.parent = parent; 66 } 67 68 } 69 | Popular Tags |