View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*;
4   
5   import ejava.examples.orm.core.MowerPK;
6   
7   /**
8    * This class provides an example of expressing an IdClass for a compound 
9    * primary key using annotations. The primary key class does not use 
10   * annotations. All annotations are within the using class.
11   */
12  @Entity
13  @Table(name="ORMCORE_MOWER")
14  @IdClass(MowerPK.class)
15  public class Mower {
16      @Id
17      private String make;
18      @Id
19      private String model;    
20      private int size;
21      
22      public Mower() {}
23      public Mower(String make, String model) {
24          this.make = make;
25          this.model = model;
26      }
27      
28      public String getMake() { return make; }    
29      public String getModel() { return model; }
30  
31      public int getSize() { return size; }
32      public void setSize(int size) {
33          this.size = size;
34      }
35      
36      public String toString() {
37          return new StringBuilder()
38             .append(super.hashCode())
39             .append(", make=").append(make)
40             .append(", model=").append(model)
41             .append(", size=").append(size)
42             .toString();
43      }
44  }