View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class an example of what to do with extra getter/setter fields
7    * (or fields) that should not be considered part of the persistence.
8    * The getMakeModel() convenience method will cause processing to fail 
9    * because there is no matching setter(). Marking it with @Transient fixes
10   * this.
11   */
12  @Entity
13  @Table(name="ORMCORE_TANK")
14  public class Tank {
15      private long id;
16      private String make;
17      private String model;
18      
19      public Tank() {}
20      public Tank(long id) { this.id = id; }
21      
22      @Id 
23      public long getId() { return id; }
24      protected void setId(long id) {
25          this.id = id;
26      }
27          
28      @Transient    //if you remove this, it will fail trying to locate setter
29      public String getMakeModel() {
30          return make + " " + model;
31      }
32      
33      public String getMake() { return make; }
34      public void setMake(String make) {
35          this.make = make;
36      }
37  
38      public String getModel() { return model; }
39      public void setModel(String model) {
40          this.model = model;
41      }
42  
43      public String toString() {
44          return new StringBuilder()
45             .append(super.toString())	       
46             .append("make=").append(make)
47             .append(", model=").append(model)
48             .toString();
49      }
50  }