ShippingDestination
新しいエンティティがまだ存在しない場合にのみ保存したいエンティティがあります。正確に一致する必要があります。
HibernateまたはSpringはこれを支援できますか、それともこの部分はすべて私次第ですか?
@javax.persistence.Table(name = "Shipping_Destination", schema = "", catalog = "production_queue")
@Entity
public class ShippingDestination {
private Integer id;
@javax.persistence.Column(name = "id", nullable = false, insertable = true, updatable = true, length = 10, precision = 0)
@Id
@GeneratedValue
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
private String recipient;
@javax.persistence.Column(name = "recipient", nullable = false, insertable = true, updatable = true, length = 32, precision = 0)
@Basic
public String getRecipient() {
return recipient;
}
@JsonProperty("Recipient")
public void setRecipient(String recipient) {
this.recipient = recipient;
}
private String street;
@javax.persistence.Column(name = "street", nullable = false, insertable = true, updatable = true, length = 255, precision = 0)
@Basic
public String getStreet() {
return street;
}
@JsonProperty("Street")
public void setStreet(String street) {
this.street = street;
}
private String street2;
@javax.persistence.Column(name = "street2", nullable = false, insertable = true, updatable = true, length = 255, precision = 0)
@Basic
public String getStreet2() {
return street2;
}
@JsonProperty("Street2")
public void setStreet2(String street2) {
this.street2 = street2;
}
private String city;
@javax.persistence.Column(name = "city", nullable = false, insertable = true, updatable = true, length = 128, precision = 0)
@Basic
public String getCity() {
return city;
}
@JsonProperty("City")
public void setCity(String city) {
this.city = city;
}
private String state;
@javax.persistence.Column(name = "state", nullable = false, insertable = true, updatable = true, length = 2, precision = 0)
@Basic
public String getState() {
return state;
}
@JsonProperty("State")
public void setState(String state) {
this.state = state;
}
private String postalCode;
@javax.persistence.Column(name = "postal_code", nullable = false, insertable = true, updatable = true, length = 12, precision = 0)
@Basic
public String getPostalCode() {
return postalCode;
}
@JsonProperty("PostalCode")
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ShippingDestination that = (ShippingDestination) o;
if (city != null ? !city.equals(that.city) : that.city != null) return false;
if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (postalCode != null ? !postalCode.equals(that.postalCode) : that.postalCode != null) return false;
if (recipient != null ? !recipient.equals(that.recipient) : that.recipient != null) return false;
if (state != null ? !state.equals(that.state) : that.state != null) return false;
if (street != null ? !street.equals(that.street) : that.street != null) return false;
return true;
}
@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (recipient != null ? recipient.hashCode() : 0);
result = 31 * result + (street != null ? street.hashCode() : 0);
result = 31 * result + (city != null ? city.hashCode() : 0);
result = 31 * result + (state != null ? state.hashCode() : 0);
result = 31 * result + (postalCode != null ? postalCode.hashCode() : 0);
return result;
}
private Collection<Order> orders;
@OneToMany(mappedBy = "shippingDestination")
public Collection<Order> getOrders() {
return orders;
}
public void setOrders(Collection<Order> orders) {
this.orders = orders;
}
private Collection<Vendor> vendors;
@OneToMany(mappedBy = "shippingDestination")
public Collection<Vendor> getVendors() {
return vendors;
}
public void setVendors(Collection<Vendor> vendors) {
this.vendors = vendors;
}
public boolean validate() throws InvalidParameterException {
if (getRecipient() == null || getRecipient().length() == 0) {
throw new InvalidParameterException("Address requires a recipient");
}
if (getStreet() == null || getStreet().length() == 0) {
throw new InvalidParameterException("Address requires a street");
}
if (getCity() == null || getCity().length() == 0) {
throw new InvalidParameterException("Address requires a city");
}
if (getState() == null || getState().length() == 0) {
throw new InvalidParameterException("Address requires a state");
}
if (getPostalCode() == null || getPostalCode().length() == 0) {
throw new InvalidParameterException("Address requires a postal code");
}
return true;
}
}