1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.test.document.bo;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import javax.persistence.CascadeType;
22 import javax.persistence.Column;
23 import javax.persistence.Entity;
24 import javax.persistence.FetchType;
25 import javax.persistence.GeneratedValue;
26 import javax.persistence.Id;
27 import javax.persistence.JoinColumn;
28 import javax.persistence.OneToMany;
29 import javax.persistence.Table;
30
31 import org.kuali.rice.krad.data.jpa.eclipselink.PortableSequenceGenerator;
32
33 @Entity
34 @Table(name="KRTST_PARENT_GEN_KEY_T")
35 public class ParentObjectWithGeneratedKey {
36
37 @Id
38 @Column(name="GENERATED_PK_COL",length=8,precision=0)
39 @GeneratedValue(generator="KRTST_GENERATED_PK_S")
40 @PortableSequenceGenerator(name="KRTST_GENERATED_PK_S")
41 Long generatedKey;
42
43 @OneToMany(fetch=FetchType.LAZY,cascade= {CascadeType.ALL}, orphanRemoval=true)
44 @JoinColumn(name="GENERATED_PK_COL",referencedColumnName="GENERATED_PK_COL",updatable=false,insertable=false)
45 List<ChildOfParentObjectWithGeneratedKey> children = new ArrayList<ChildOfParentObjectWithGeneratedKey>();
46
47 public Long getGeneratedKey() {
48 return this.generatedKey;
49 }
50
51 public void setGeneratedKey(Long generatedKey) {
52 this.generatedKey = generatedKey;
53 }
54
55 public List<ChildOfParentObjectWithGeneratedKey> getChildren() {
56 return this.children;
57 }
58
59 public void setChildren(List<ChildOfParentObjectWithGeneratedKey> children) {
60 this.children = children;
61 }
62
63 public ChildOfParentObjectWithGeneratedKey getChildByKey( Long childKey ) {
64 for ( ChildOfParentObjectWithGeneratedKey child : children ) {
65 if ( child.childKey.equals(childKey) ) {
66 return child;
67 }
68 }
69 return null;
70 }
71
72 @Override
73 public String toString() {
74 StringBuilder builder = new StringBuilder();
75 builder.append("ParentObjectWithGeneratedKey [");
76 if (this.generatedKey != null) {
77 builder.append("generatedKey=").append(this.generatedKey).append(", ");
78 }
79 if (this.children != null) {
80 builder.append("children=").append(this.children);
81 }
82 builder.append("]");
83 return builder.toString();
84 }
85
86
87 }