1 package ejava.examples.orm.inheritance.annotated;
2
3 import javax.persistence.*;
4
5
6
7
8
9
10
11
12
13
14
15 @Entity
16 @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
17 @SequenceGenerator(
18 name="orminhSeq",
19 sequenceName="ORMINH_SEQ"
20 )
21 public abstract class Account {
22 @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="orminhSeq")
23 private long id;
24 private double balance;
25
26 public Account() {}
27 public Account(long id) { this.id=id; }
28 public long getId() { return id; }
29
30 public double getBalance() { return balance; }
31 public void setBalance(double balance) {
32 this.balance = balance;
33 }
34
35 public void deposit(double amount) throws AccountException {
36 setBalance(getBalance() + amount);
37 }
38 public abstract void withdraw(double amount) throws AccountException;
39 public void processInterest() {}
40
41 public String toString() {
42 StringBuilder text = new StringBuilder(super.toString());
43 text.append(", id=" + id);
44 text.append(", balance=" + balance);
45 return text.toString();
46 }
47 }