View Javadoc
1   package myorg.relex.collection;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import javax.persistence.*;
7   
8   /**
9    * This class provides an example of a parent that uses a Map to reference child members.
10   */
11  @Entity
12  @Table(name="RELATIONEX_LINEUP")
13  public class Lineup {
14  	@Id @GeneratedValue
15  	private int id;
16  	
17  	@OneToMany
18  	@MapKey(name="position")
19  	@JoinColumn(name="LINEUP_ID")
20  	private Map<String, Position> positions;
21  	
22  	@Column(length=10)
23  	private String team;
24  
25  	public int getId() { return id; }
26  
27  	public Map<String, Position> getPositions() {
28  		if (positions==null) { positions = new HashMap<String, Position>(); }
29  		return positions; 
30  	}
31  	public Lineup addPosition(Position position) {
32  		if (position==null) { return this; }
33  		getPositions().put(position.getPosition(), position);
34  		return this;
35  	}
36  
37  	public String getTeam() { return team; }
38  	public void setTeam(String team) {
39  		this.team = team;
40  	}
41  }