1 package ejava.examples.orm.inheritance.annotated;
2
3 import javax.persistence.*;
4
5
6
7
8
9
10
11
12 @Entity @Table(name="ORMINH_PRODUCT")
13 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
14 @DiscriminatorColumn(name="PTYPE",
15 discriminatorType=DiscriminatorType.STRING,
16 length=32)
17 public abstract class Product {
18 @Id @GeneratedValue
19 private long id;
20 private double cost;
21
22 protected Product() {}
23 protected Product(long id) { this.id=id; }
24 public long getId() { return id; }
25
26 public double getCost() {
27 return cost;
28 }
29 public void setCost(double cost) {
30 this.cost = cost;
31 }
32
33 @Transient
34 public abstract String getName();
35
36 public String toString() {
37 StringBuilder text = new StringBuilder(super.toString());
38 text.append(", id=" + id);
39 text.append(", cost=" + cost);
40 return text.toString();
41 }
42 }