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 sub-class that is part of a 
9    * single table inheritance strategy. The table and primary key generation is 
10   * being defined by the parent class. This class is accepting all defaults. 
11   * @see Bead class for a sibling example of overriding the discriminator value.
12   */
13  @Entity
14  public class Soup extends Product {
15      public enum SoupType {
16          UNKNOWN("Unknown"),
17          CHICKEN_NOODLE("Chicken Noodle"), 
18          NEW_ENGLAND_CLAM_CHOWDER("New England Clam Chowder"), 
19          TOMATO("Tomato");
20          private String text;
21          private SoupType(String text) { this.text = text; }
22          public String text() { return text; }
23      };
24  
25      @Enumerated(EnumType.STRING)
26      @Column(name="SOUPTYPE", length=16)
27      private SoupType type = SoupType.UNKNOWN;
28      @Temporal(TemporalType.DATE)
29      private Date expiration;
30      
31      public Soup() {}
32      public Soup(long id) { super(id); }
33  
34      public Date getExpiration() { return expiration; }
35      public void setExpiration(Date expiration) {
36          this.expiration = expiration;
37      }
38  
39      public SoupType getSoupType() { return type; }
40      public void setSoupType(SoupType type) {
41          this.type = type;
42      }
43  
44      @Transient
45      public String getName() { return type.text() + "Soup"; }
46      
47      public String toString() {
48          StringBuilder text = new StringBuilder(super.toString());
49          text.append(", type=" + type);
50          text.append(", expiration=" + expiration);
51          return text.toString();
52      }
53  }