View Javadoc
1   package myorg.relex.many2one;
2   
3   import javax.persistence.*;
4   
5   /**
6    * This class provides an example of the owning/child side of a many-to-one, uni-directional relationship
7    * where the parent uses a (embedded) compound primary key.
8    */
9   @Entity
10  @Table(name="RELATIONEX_OCCUPANT")
11  public class Occupant {
12  	@Id @GeneratedValue
13  	private int id;
14  	
15  	@ManyToOne(optional=false)
16  	@JoinColumns({
17  			@JoinColumn(name="RES_NUM", referencedColumnName="NO"),
18  			@JoinColumn(name="RES_STR", referencedColumnName="STREET_NAME")
19  	})
20  	private House residence;
21  	
22  	@Column(length=16, nullable=false)
23  	private String name;
24  
25  	protected Occupant(){}
26  	public Occupant(String name, House residence) {
27  		this.name = name;
28  		this.residence = residence;
29  	}
30  	
31  	public int getId() { return id; }
32  
33  	public House getResidence() { return residence; }
34  	public void setResidence(House residence) {
35  		this.residence = residence;
36  	}
37  
38  	public String getName() { return name; }
39  	public void setName(String name) {
40  		this.name = name;
41  	}
42  }