View Javadoc
1   package myorg.relex.one2many;
2   
3   import java.util.HashSet;
4   import java.util.Set;
5   import javax.persistence.*;
6   
7   /**
8    * This class provides an example of the owning side of a collection of base data types.
9    * In this case we want a unique set of strings (aliases) mapped to this entity using
10   * a separate dependent table and a foreign key relationship.
11   */
12  @Entity
13  @Table(name="RELATIONEX_SUSPECT")
14  public class Suspect {
15  	@Id @GeneratedValue
16  	private int id;
17  	@Column(length=32)
18  	private String name;
19  		
20  	@ElementCollection
21  	@CollectionTable(
22  			name="RELATIONEX_SUSPECT_ALIASES",
23  			joinColumns=@JoinColumn(name="SUSPECT_ID"), 
24  			uniqueConstraints=@UniqueConstraint(columnNames={"SUSPECT_ID", "ALIAS"}))
25  	@Column(name="ALIAS", length=32)
26  	private Set<String> aliases;
27  
28  	public int getId() { return id; }
29  
30  	public String getName() { return name; }
31  	public void setName(String name) {
32  		this.name = name;
33  	}
34  
35  	public Set<String> getAliases() {
36  		if (aliases==null) { aliases = new HashSet<String>(); }
37  		return aliases;
38  	}
39  	public void setAliases(Set<String> aliases) {
40  		this.aliases = aliases;
41  	}
42  }