View Javadoc
1   package ejava.examples.orm.inheritance.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of an entity sub-class using separate
7    * classes per-concrete derived class. This means that the base class
8    * properties will get merged into this table (similar to non-entity 
9    * inheritance).
10   */
11  @Entity
12  @Table(name="ORMINH_INTERESTACCT")
13  public class InterestAccount extends Account {
14      private double rate;
15      
16      public InterestAccount() {}
17      public InterestAccount(long id) { super(id); }
18  
19      public void withdraw(double amount) throws AccountException {
20          super.setBalance(super.getBalance() - amount);
21      }
22      
23      public void processInterest() {
24          super.setBalance(super.getBalance() * (1 + rate)); 
25      }
26  
27      public double getRate() {
28          return rate;
29      }
30  
31      public void setRate(double rate) {
32          this.rate = rate;
33      }
34  
35      public String toString() {
36          StringBuilder text = new StringBuilder(super.toString());
37          text.append(", rate=" + rate);
38          return text.toString();
39      }
40  }