View Javadoc
1   package ejava.examples.orm.inheritance.annotated;
2   
3   import java.util.Date;
4   
5   import javax.persistence.*;
6   
7   /**
8    * This class provides an example of an entity that is part of a single table
9    * inheritance approach. In this case, all derived classes will be merged into
10   * a single table defined by the parent class. This class defines its 
11   * discriminiator value. @see Soup class for a sibling example where the 
12   * default value is taken.
13   */
14  @Entity
15  @DiscriminatorValue("BREAD_TYPE") //value placed in root table to indicate type
16  public class Bread extends Product {
17      private int slices;
18      @Temporal(TemporalType.DATE)
19      private Date bakedOn;
20      
21      public Bread() {}
22      public Bread(long id) { super(id); }
23  
24      public Date getBakedOn() { return bakedOn;}
25      public void setBakedOn(Date bakedOn) {
26          this.bakedOn = bakedOn;
27      }
28  
29      public int getSlices() { return slices; }
30      public void setSlices(int slices) { 
31      	this.slices = slices; 
32      }
33  
34      @Transient
35      public String getName() { return "Bread"; }
36  
37      public String toString() {
38          StringBuilder text = new StringBuilder(super.toString());
39          text.append(", slices=" + slices);
40          text.append(", baked=" + bakedOn);
41          return text.toString();
42      }
43  }