1 package org.hibernate.test.cid; 3 4 import java.io.Serializable ; 5 6 9 public class LineItem { 10 public static class Id implements Serializable { 11 private String customerId; 12 private int orderNumber; 13 private String productId; 14 15 public Id(String customerId, int orderNumber, String productId) { 16 this.customerId = customerId; 17 this.orderNumber = orderNumber; 18 this.productId = productId; 19 } 20 public Id() {} 21 22 25 public String getCustomerId() { 26 return customerId; 27 } 28 31 public void setCustomerId(String customerId) { 32 this.customerId = customerId; 33 } 34 37 public String getProductId() { 38 return productId; 39 } 40 43 public void setProductId(String productId) { 44 this.productId = productId; 45 } 46 49 public int getOrderNumber() { 50 return orderNumber; 51 } 52 55 public void setOrderNumber(int orderNumber) { 56 this.orderNumber = orderNumber; 57 } 58 public int hashCode() { 59 return customerId.hashCode() + orderNumber + productId.hashCode(); 60 } 61 public boolean equals(Object other) { 62 if (other instanceof Id) { 63 Id that = (Id) other; 64 return that.customerId.equals(this.customerId) && 65 that.productId.equals(this.productId) && 66 that.orderNumber == this.orderNumber; 67 } 68 else { 69 return false; 70 } 71 } 72 } 73 74 private Id id = new Id(); 75 private int quantity; 76 private Order order; 77 private Product product; 78 79 public LineItem(Order o, Product p) { 80 this.order = o; 81 this.id.orderNumber = o.getId().getOrderNumber(); 82 this.id.customerId = o.getId().getCustomerId(); 83 this.id.productId = p.getProductId(); 84 o.getLineItems().add(this); 85 } 86 87 public LineItem() {} 88 89 92 public Order getOrder() { 93 return order; 94 } 95 98 public void setOrder(Order order) { 99 this.order = order; 100 } 101 104 public Product getProduct() { 105 return product; 106 } 107 110 public void setProduct(Product product) { 111 this.product = product; 112 } 113 116 public int getQuantity() { 117 return quantity; 118 } 119 122 public void setQuantity(int quantity) { 123 this.quantity = quantity; 124 } 125 128 public Id getId() { 129 return id; 130 } 131 134 public void setId(Id id) { 135 this.id = id; 136 } 137 } 138 | Popular Tags |