/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.envers.test.integration.naturalid;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import org.hibernate.annotations.NaturalId;
import org.hibernate.envers.Audited;
/**
* @author Chris Cranford
*/
@Entity
@Audited
public class Customer implements Serializable {
@Id
@GeneratedValue
private Integer id;
@NaturalId
private String customerNumber;
@NaturalId
private String name;
@Audited
@OneToMany(mappedBy = "customer")
private Collection<Account> accounts = new ArrayList<Account>();
@OneToMany(mappedBy = "customer", cascade = CascadeType.ALL)
private Set<Device> devices = new HashSet<Device>();
Customer() {
}
Customer(Integer id, String customerNumber, String name) {
this.id = id;
this.customerNumber = customerNumber;
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Collection<Account> getAccounts() {
return accounts;
}
public void setAccounts(Collection<Account> accounts) {
this.accounts = accounts;
}
public Set<Device> getDevices() {
return devices;
}
public void setDevices(Set<Device> devices) {
this.devices = devices;
}
@Override
public int hashCode() {
int result;
result = ( id != null ? id.hashCode() : 0 );
result = 31 * result + ( customerNumber != null ? customerNumber.hashCode() : 0 );
result = 31 * result + ( name != null ? name.hashCode() : 0 );
return result;
}
@Override
public boolean equals(Object obj) {
if ( obj == this ) {
return true;
}
if ( !( obj instanceof Customer ) ) {
return false;
}
Customer that = (Customer) obj;
if ( id != null ? !id.equals( that.id ) : that.id != null ) {
return false;
}
if ( name != null ? !name.equals( that.name ) : that.name != null ) {
return false;
}
return true;
}
@Override
public String toString() {
return "Customer{" +
"id=" + id +
", name='" + name + '\'' +
", customerNumber='" + customerNumber + '\'' +
", accounts=" + accounts +
", devices=" + devices +
'}';
}
}