View Javadoc
1   package ejava.examples.orm.core.annotated;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of embedding another object within a 
7    * containing object being mapped to the database. In this case, XRay is
8    * assigned a primary key and mapped to the database. It has two local 
9    * properties, but maker name, address, and phone are part of a Manufacturer
10   * class. This works much like the @EmbeddedId case, except the embedded class
11   * is just used for normal properties and not primary key values.
12   */
13  @Entity
14  @Table(name="ORMCORE_XRAY")
15  public class XRay {
16      @Id
17      private long id;
18      @Embedded
19      @AttributeOverrides({
20          @AttributeOverride(name="name", column=@Column(name="XRAY_MAKER"))
21          //note that we are letting address and phone default 
22      })
23      private Manufacturer maker;
24      private String model;
25      
26      public XRay() {}
27      public XRay(long id) { this.id = id; }
28      
29      public long getId() { return id; }
30  
31      public String getModel() { return model; }
32      public void setModel(String model) {
33          this.model = model;
34      }
35      
36      public Manufacturer getMaker() { return maker; }
37      public void setMaker(Manufacturer maker) {
38          this.maker = maker;
39      }
40      
41      public String toString() {
42          return new StringBuilder()
43             .append(super.getClass().getName())
44             .append(", id=").append(id)
45             .append(", model=").append(model)
46             .append(", maker=").append(maker)
47             .toString();
48      }
49  }