
test.googlecode.genericdao.model.Pet Maven / Gradle / Ivy
/* Copyright 2009 The Revere Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test.googlecode.genericdao.model;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToOne;
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "limbed", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")
public class Pet {
private Long id;
private Ident ident;
private String species;
private Pet favoritePlaymate;
public Pet() {}
public Pet(String species, String firstName, String lastName, Integer idNumber ) {
this.species = species;
this.ident = new Ident();
this.ident.setIdNumber(idNumber);
this.ident.setName(new Name());
this.ident.getName().setFirst(firstName);
this.ident.getName().setLast(lastName);
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getSpecies() {
return species;
}
public void setSpecies(String species) {
this.species = species;
}
public Ident getIdent() {
return ident;
}
public void setIdent(Ident ident) {
this.ident = ident;
}
@ManyToOne
public Pet getFavoritePlaymate() {
return favoritePlaymate;
}
public void setFavoritePlaymate(Pet favoritePlaymate) {
this.favoritePlaymate = favoritePlaymate;
}
public String toString() {
return "Pet::id:" + id + ",ident:" + ident + ",species:" + species + ",favoritePlaymateId:" + favoritePlaymate.getId();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((ident == null) ? 0 : ident.hashCode());
result = prime * result + ((species == null) ? 0 : species.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;
Pet other = (Pet) obj;
if (ident == null) {
if (other.ident != null)
return false;
} else if (!ident.equals(other.ident))
return false;
if (species == null) {
if (other.species != null)
return false;
} else if (!species.equals(other.species))
return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy