View Javadoc
1   package ejava.examples.orm.inheritance.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of inheriting from a non-entity base class.
7    * In this case, the base class is mapped into the Album table. We physically
8    * map the parent properties into table colums here. 
9    * @see Toothpaste class for a sibling example that will accept the parent
10   * mapping defaults.
11   */
12  @Entity 
13  @Table(name="ORMINH_ALBUM") //this table holds both this entity and parent class
14  @AttributeOverrides({
15      @AttributeOverride(name="version", column=@Column(name="ALBUM_VERSION"))
16  })
17  public class Album extends BaseObject {
18  	@Access(AccessType.FIELD)
19      private String artist;
20  	@Access(AccessType.FIELD)
21      private String title;
22  
23      @Id @GeneratedValue //id is being generated independent of other siblings
24      @Column(name="ALBUM_ID") 
25      public long getId() { return super.getId(); }
26      protected void setId(long id) {
27          super.setId(id);
28      }
29      
30      public String getArtist() { return artist; }
31      public void setArtist(String artist) {
32          this.artist = artist;
33      }
34      
35      public String getTitle() { return title; }
36      public void setTitle(String title) {
37          this.title = title;
38      }
39  
40      @Transient
41      public String getName() { return artist + ":" + title; }
42      
43      public String toString() {
44          StringBuilder text = new StringBuilder(super.toString());
45          return text.toString();
46      }
47  }