View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*; //brings in JPA Annotations
4   
5   /**
6    * This class provides the basic annotations required to make a class usable 
7    * by Java Persistence without any further mapping. They are 
8    * @javax.persistence.Entity to denote the class and @javax.persistence.Id
9    * to denote the primary key property. See the mapped Bike example of how this 
10   * can be done through a deployment descriptor instead of annotations. 
11   */
12  @Entity  //tells ORM that this class can be mapped 
13  @Table(uniqueConstraints=@UniqueConstraint(columnNames={"make","model"}))
14  public class Bike {
15      @Id   //tells ORM that this property provides pk simple value
16      private long id;
17      private String make;
18      private String model;
19      private int size;
20      
21      public Bike() {} //required non-private default ctor
22      public Bike(long id) { this.id = id; }
23  
24      public long getId() { return id; }
25  
26      public String getMake() { return make; }
27      public void setMake(String make) {
28          this.make = make;
29      }
30      
31      public String getModel() { return model; }
32      public void setModel(String model) {
33          this.model = model;
34      }
35      
36      public int getSize() { return size; }
37      public void setSize(int size) {
38          this.size = size;
39      }
40      
41  	@Override
42  	public String toString() {
43  		StringBuilder builder = new StringBuilder();
44  		builder.append(super.toString())
45  		       .append(", id=").append(id)
46  		       .append(", make=").append(make)
47  			   .append(", model=").append(model)
48  			   .append(", size=").append(size).append("in");
49  		return builder.toString();
50  	}    
51  }