package elh.maayan.test;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
@Entity
@SequenceGenerator(sequenceName = "seq", name = "seq")
public class Supplier {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
private long id;
private long ssn;
public long getSsn() {
return this.ssn;
}
public void setSsn(final long ssn) {
this.ssn = ssn;
}
public long getId() {
return this.id;
}
public Supplier() {
}
public Supplier(final String name) {
super();
this.name = name;
}
public void setId(final long id) {
this.id = id;
}
private String name;
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@JoinColumn(name = "contracts")
private Set<Contract> contracts = new HashSet<Contract>();
public Collection<Contract> getContracts() {
return this.contracts;
}
public void setContracts(final Collection<Contract> contracts) {
this.contracts = (Set<Contract>) contracts;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (this.ssn ^ (this.ssn >>> 32));
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Supplier other = (Supplier) obj;
if (this.ssn != other.ssn) {
return false;
}
return true;
}
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}
}