View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import java.util.Date;
4   
5   import javax.persistence.*;
6   
7   import ejava.examples.orm.core.ColorType;
8   
9   /**
10   * This class provides an example of mapping various types to the database,
11   * like dates, enums, etc.
12   */
13  @Entity
14  @Table(name="ORMCORE_VASE")
15  public class Vase {
16      @Id
17      private long id;
18      @Temporal(TemporalType.DATE)
19      private Date aDate;
20      @Temporal(TemporalType.TIME)
21      private Date aTime;
22      @Temporal(TemporalType.TIMESTAMP)
23      private Date aTimestamp;
24      @Enumerated(EnumType.ORDINAL)
25      private ColorType colorId;
26      @Enumerated(EnumType.STRING)
27      private ColorType colorName;
28  
29      public Vase() {}
30      public Vase(long id) { this.id = id; }
31  
32      public long getId() { return id; }
33      
34      public Date getADate() { return aDate; }
35      public void setADate(Date date) {
36          aDate = date;
37      }
38      
39      public Date getATime() { return aTime; }
40      public void setATime(Date time) {
41          aTime = time;
42      }
43      
44      public Date getATimestamp() { return aTimestamp; }
45      public void setATimestamp(Date timestamp) {
46          aTimestamp = timestamp;
47      }
48      
49      public ColorType getColorId() { return colorId; }
50      public void setColorId(ColorType colorId) {
51          this.colorId = colorId;
52      }
53  
54      public ColorType getColorName() { return colorName; }
55      public void setColorName(ColorType colorName) {
56          this.colorName = colorName;
57      }
58      
59      @Override
60      public String toString() {
61          StringBuilder builder = new StringBuilder();
62          builder.append(super.toString())
63             .append(", id=").append(id)
64             .append(", aDate=").append(aDate)
65                 .append(", aTime=").append(aTime)
66                 .append(", aTimestamp=").append(aTimestamp)
67                 .append(", colorId=").append(colorId)
68                 .append(", colorName=").append(colorName);
69          return builder.toString();
70      }
71  }
72