View Javadoc
1   package ejava.examples.orm.rel.annotated;
2   
3   import javax.persistence.*;
4   
5   import org.apache.commons.logging.Log;
6   import org.apache.commons.logging.LogFactory;
7   
8   /**
9    * This class provides an example of the "inverse side" of a OneToOne 
10   * Uni-directional relationship. This object will be "owned" by the Person
11   * object.
12   */
13  @Entity
14  @Table(name="ORMREL_PHOTO")
15  public class Photo {
16      private static Log log = LogFactory.getLog(Photo.class);
17  
18      @Id @GeneratedValue @Column(name="PHOTO_ID")
19      private long id;
20      @Lob
21      private byte[] image;
22      
23      
24      public Photo() { log.debug(super.toString() + ": ctor()"); }
25      public Photo(byte[] image) { 
26          log.debug(super.toString() + ": ctor() image=" + image); 
27          this.image = image;
28      }
29      
30      public long getId() {
31          log.debug(super.toString() + ": getId()=" + id);
32          return id;
33      }
34      
35      public byte[] getImage() { return image; }
36      public void setImage(byte[] image) {
37          this.image = image;
38      }          
39  
40      public String toString() {
41          long size = (image == null) ? 0 : image.length;
42          String sizeText = 
43              (image == null) ? "null" : new Long(size).toString() + " bytes";
44          return super.toString() +
45              ", id=" + id +
46              ". image=" + sizeText;
47      }
48  }