1 package ejava.examples.orm.rel.composite;
2
3 import javax.persistence.*;
4
5
6
7
8
9 @Entity @Table(name="ORMREL_ROOM")
10 @IdClass(RoomPK.class)
11 @AttributeOverrides({
12 @AttributeOverride(name = "houseId", column=@Column(name="HOUSE_ID")),
13 @AttributeOverride(name = "roomId", column=@Column(name="ROOM_ID"))
14 })
15 public class Room {
16 @Id
17 private int houseId;
18 @Id
19 private int roomId;
20
21 @ManyToOne(fetch=FetchType.LAZY, optional=false)
22
23 @JoinColumn(name="HOUSE_ID", insertable=false, updatable=false)
24 private House house;
25
26 public Room() {}
27 public Room(House house, int roomId) {
28 this.houseId=house.getId();
29 this.house=house;
30 this.roomId=roomId;
31 }
32
33 public House getHouse() { return house; }
34 public int getRoomId() { return roomId; }
35 }