View Javadoc
1   package ejava.examples.orm.core.mapped;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of embedding a primary key class within
7    * the conatining class and doing all the mapping if the PK here instead
8    * of the PK class. Note that we are able to better generalize the PK class
9    * because of where the mapping is placed.
10   */
11  @Entity
12  @Table(name="ORMCORE_PEN")
13  public class Pen {
14      @EmbeddedId
15      @AttributeOverrides({
16          @AttributeOverride(name="make", column=@Column(name="PEN_MAKE")),
17          @AttributeOverride(name="model", column=@Column(name="PEN_MODEL"))             
18          })
19      private MakeModelPK pk;
20      private int size;
21      
22      public Pen() {}
23      public Pen(String make, String model) {
24          this.pk = new MakeModelPK(make, model);
25      }
26      
27      public MakeModelPK getPk() { return pk; }
28      
29      public int getSize() { return size; }
30      public void setSize(int size) {
31          this.size = size;
32      }
33      
34      public String toString() {
35          return super.toString() +
36             ", pk=" + pk +
37             ", size=" + size;
38      }
39  }