1 package xpetstore.domain.catalog.ejb; 2 3 import java.util.Collection ; 4 5 import javax.persistence.CascadeType; 6 import javax.persistence.Column; 7 import javax.persistence.Entity; 8 import javax.persistence.Id; 9 import javax.persistence.JoinColumn; 10 import javax.persistence.ManyToOne; 11 import javax.persistence.OneToMany; 12 13 import javax.persistence.Table; 14 15 16 37 @Entity(name="Product") 38 @Table(name="T_PRODUCT") 39 public class Product 40 { 41 private String productId; 42 private String name; 43 private String description; 44 private Collection items; 45 private Category category; 46 47 public Product() 48 { 49 50 } 51 52 public Product(String productId, String name, String description) 53 { 54 this.productId = productId; 55 this.name = name; 56 this.description = description; 57 } 58 59 69 @Id 70 @Column(name="productId", length=10) 71 public String getProductId( ) 72 { 73 return productId; 74 } 75 76 public void setProductId( String productId ) 77 { 78 this.productId = productId; 79 } 80 81 87 @Column(name="name", length=50) 88 public String getName( ) 89 { 90 return name; 91 } 92 93 public void setName( String name ) 94 { 95 this.name = name; 96 } 97 98 104 @Column(name="description", length=255) 105 public String getDescription( ) 106 { 107 return description; 108 } 109 110 public void setDescription( String description ) 111 { 112 this.description = description; 113 } 114 115 121 @OneToMany(targetEntity=Item.class, cascade={CascadeType.ALL}) 122 @JoinColumn(name="PRODUCT_ID") 123 public Collection getItems( ) 124 { 125 return items; 126 } 127 128 public void setItems( Collection items ) 129 { 130 this.items = items; 131 } 132 133 148 @ManyToOne(cascade={CascadeType.ALL}) 149 @JoinColumn(name="CATEGORY_ID") 150 public Category getCategory( ) 151 { 152 return category; 153 } 154 155 public void setCategory( Category category ) 156 { 157 this.category = category; 158 } 159 160 public String toString() 161 { 162 StringBuffer buffer = new StringBuffer (200); 163 buffer.append("[Product: productId " + productId); 164 buffer.append(", name " + name); 165 buffer.append("]"); 166 167 return buffer.toString(); 168 } 169 170 } 171 | Popular Tags |