View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class demonstrates the use of SEQUENCE generator strategy using
7    * annotations.
8    */
9   @Entity
10  @Table(name="ORMCORE_FAN")
11  @SequenceGenerator(
12      name="fanSequence",     //required logical name
13      sequenceName="FAN_SEQ", //name in database
14      initialValue=5,         //start with something odd to be noticeable
15      allocationSize=3)       //number of IDs to internally assign per-sequence value
16  public class Fan {
17      @Id
18      @GeneratedValue(strategy=GenerationType.SEQUENCE, //use DB sequence 
19              generator="fanSequence")                  //point to logical def
20      private long id;
21      private String make;    
22      
23      public Fan() {}
24      public Fan(long id) { this.id = id; }
25      
26      public long getId() { return id; }
27  
28      public String getMake() { return make; }
29      public void setMake(String make) {
30          this.make = make;
31      }
32  
33      @Override
34      public String toString() {
35          return new StringBuilder()
36                .append(super.hashCode())
37                .append(", id=").append(id)
38                .append(", make=").append(make)
39                .toString();
40      }    
41  }