Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.model;
- import javax.persistence.Column;
- import javax.persistence.Entity;
- import javax.persistence.GeneratedValue;
- import javax.persistence.GenerationType;
- import javax.persistence.Id;
- import javax.persistence.OneToOne;
- import javax.persistence.Table;
- import org.springframework.beans.factory.annotation.Required;
- @Entity
- @Table(name = "email_contact")
- public class EmailContact extends BaseObject {
- private static final long serialVersionUID = 6643356695108989062L;
- private Long id;
- private Customer customer;
- private String emailAddress;
- public EmailContact() {
- super();
- }
- public EmailContact(String emailAddress) {
- super();
- this.emailAddress = emailAddress;
- }
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- @OneToOne
- @Required
- public Customer getCustomer() {
- return customer;
- }
- public void setCustomer(Customer customer) {
- if (this.customer != null && !this.customer.equals(customer)) {
- throw new RuntimeException("Invalid state: Customer cannot be changed on an existing EmailContact");
- }
- this.customer = customer;
- }
- @Column(name = "email_address", length = 255)
- @Required
- public String getEmailAddress() {
- return emailAddress;
- }
- public void setEmailAddress(String emailAddress) {
- this.emailAddress = emailAddress;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((customer == null) ? 0 : customer.hashCode());
- result = prime * result + ((emailAddress == null) ? 0 : emailAddress.hashCode());
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- EmailContact other = (EmailContact) obj;
- if (customer == null) {
- if (other.customer != null)
- return false;
- } else if (!customer.equals(other.customer))
- return false;
- if (emailAddress == null) {
- if (other.emailAddress != null)
- return false;
- } else if (!emailAddress.equals(other.emailAddress))
- return false;
- return true;
- }
- @Override
- public String toString() {
- return "EmailContact [id=" + (id == null ? "null" : id.toString()) + ", customer=" + (customer==null?"null":customer.getCustomerNumber()) + ", emailAddress=" + emailAddress + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement