1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
@Entity
public class LigneCommandeClient {
@Embeddable
public static class Id implements Serializable{
private static final long serialVersionUID = 1L;
@Column(name="product_id")
private Long productId;
@Column(name="cmde_id")
private Long cmdeId;
public Long getCmdeId() {
return cmdeId;
}
public void setCmdeId(Long cmdeId) {
this.cmdeId = cmdeId;
}
public Long getProductId() {
return productId;
}
public void setProductId(Long productId) {
this.productId = productId;
}
public Id(){}
public Id(Long productId,Long cmdeId){
this.productId=productId;
this.cmdeId=cmdeId;
}
public boolean equals(Object o){
if(o!=null && o instanceof Id){
Id that=(Id)o;
return this.productId.equals(that.productId)&& this.cmdeId.equals(that.cmdeId);
}
else{
return false;
}
}
public int hashCode(){
return productId.hashCode()+cmdeId.hashCode();
}
}
private Id id=new Id();
private Produit product;
private CommandeClient cmdeclient;
private long quantite;
public LigneCommandeClient(){}
public LigneCommandeClient(long quantite,Produit product,CommandeClient cmdeclient){
//set Fields
this.quantite=quantite;
this.product=product;
this.cmdeclient=cmdeclient;
//set identifier values
this.id.setCmdeId(cmdeclient.getId());
this.id.setProductId(product.getId());
//Guarentee referential integrity
// product.getLigneCmdeClients().add(this);
// cmdeclient.getLigneCmdeClients().add(this);
}
@ManyToOne
@JoinColumn(name="id",insertable=false,updatable=false)
public CommandeClient getCmdeclient() {
return cmdeclient;
}
public void setCmdeclient(CommandeClient cmdeclient) {
this.cmdeclient = cmdeclient;
}
@ManyToOne
@JoinColumn(name="id",insertable=false,updatable=false)
public Produit getProduct() {
return product;
}
public void setProduct(Produit product) {
this.product = product;
}
public long getQuantite() {
return quantite;
}
public void setQuantite(long quantite) {
this.quantite = quantite;
}
@EmbeddedId
public Id getId() {
return id;
}
public void setId(Id id) {
this.id = id;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((cmdeclient == null) ? 0 : cmdeclient.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((product == null) ? 0 : product.hashCode());
result = prime * result + (int) (quantite ^ (quantite >>> 32));
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final LigneCommandeClient other = (LigneCommandeClient) obj;
if (cmdeclient == null) {
if (other.cmdeclient != null)
return false;
} else if (!cmdeclient.equals(other.cmdeclient))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (product == null) {
if (other.product != null)
return false;
} else if (!product.equals(other.product))
return false;
if (quantite != other.quantite)
return false;
return true;
}
} |