package tutorial.persistence; import javax.persistence.*; /** * Animal class for use in the pet store tutorial. */ @Entity(name = "Animal") @Table(name = "JPA_TUT_ANIMAL") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "SPECIES", length = 100) public abstract class Animal { @Id @GeneratedValue @Column(name = "ID") private long id; @Basic @Column(name = "ANIMAL_NAME") private String name; @Basic @Column(name = "COST") private float price; /** * Constructor. * * @param name This animal's name. * @param price The price of the animal, in dollars. */ public Animal(String name, float price) { this.name = name; this.price = price; } /** * Return the animal's name. */ public String getName() { return name; } /** * Return the price of the animal in dollars. */ public float getPrice() { return price; } /** * The unique ID of this animal. */ public void setId(long id) { this.id = id; } /** * The unique ID of this animal. */ public long getId() { return this.id; } /** * Return a useful informational string describing this animal. */ public String toString() { return toString(false); } /** * Return an informational string describing this animal; if * detailed is true, return * a more verbose description of the animal. * * @param detailed a boolean that controls the verbosity of the returned * string */ public abstract String toString(boolean detailed); }