View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of using a TABLE GeneratedValue schema. The
7    * definition of the primary key generation is within the annotations supplied
8    * in this class.
9    */
10  @Entity
11  @Table(name="ORMCORE_EGGBEATER")
12  @TableGenerator(  //note that all but name are optional if generating schema
13          name="eggbeaterGenerator",     //logical name of generator
14          table="ORMCORE_EB_UID",        //name of table storing seq
15          pkColumnName="UID_ID",         //pk column for seq table
16          pkColumnValue="ORMCORE_EGGBEATER",  //pk value in pk column
17          valueColumnName="UID_VAL",     //column for seq value
18          initialValue=7,               //first value database should provide
19          allocationSize=5              //increment UID_ID after using this many
20      )        
21  public class EggBeater {
22      @Id
23      @GeneratedValue(strategy=GenerationType.TABLE, //use DB table 
24              generator="eggbeaterGenerator")        //point to logical def
25      private long id;
26      private String make;    
27      
28      public EggBeater() {}
29      public EggBeater(long id) { this.id = id; }
30      
31      public long getId() { return id; }
32  
33      public String getMake() { return make; }
34      public void setMake(String make) {
35          this.make = make;
36      }
37  
38      @Override
39      public String toString() {
40              return new StringBuilder()
41                        .append(super.hashCode())	       
42                        .append(", id=").append(id)
43                        .append(", make=").append(make)
44                        .toString();
45      }    
46  }