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          allocationSize=5              //increment UID_ID after using this many
19      )        
20  public class EggBeater {
21      @Id
22      @GeneratedValue(strategy=GenerationType.TABLE, //use DB table 
23              generator="eggbeaterGenerator")        //point to logical def
24      private long id;
25      private String make;    
26      
27      public EggBeater() {}
28      public EggBeater(long id) { this.id = id; }
29      
30      public long getId() { return id; }
31  
32      public String getMake() { return make; }
33      public void setMake(String make) {
34          this.make = make;
35      }
36  
37      @Override
38      public String toString() {
39              return new StringBuilder()
40                        .append(super.toString())	       
41                        .append(", id=").append(id)
42                        .append(", make=").append(make)
43                        .toString();
44      }    
45  }