1 package ejava.examples.orm.rel.composite;
2
3 import javax.persistence.*;
4
5
6
7
8
9 @Entity @Table(name="ORMREL_MORTGAGE")
10 public class Mortgage {
11 @EmbeddedId
12 @AttributeOverrides({
13 @AttributeOverride(name="mortgageId", column=@Column(name="MORTGAGE_ID"))
14 })
15 private MortgagePK pk;
16
17 @ManyToOne(fetch=FetchType.LAZY, optional=false)
18 @JoinColumn(name="HOUSE_ID", nullable=false)
19 @MapsId("houseId")
20 private House house;
21
22 public Mortgage() {}
23 public Mortgage(House house, int mortgageId) {
24 pk=new MortgagePK(house.getId(), mortgageId);
25 this.house=house;
26 }
27
28 public MortgagePK getPk() { return pk; }
29 public House getHouse() { return house; }
30 }