View Javadoc
1   package myorg.relex.one2many;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import javax.persistence.*;
7   
8   /**
9    * This entity class provides an example of mapping a collection of non-entity/embeddable class instances
10   * to a dependent/child table and relating the child table to this entity table using a foreign key. 
11   */
12  @Entity
13  @Table(name="RELATIONEX_BASKET")
14  public class Basket {
15  	@Id @GeneratedValue
16  	private int id;
17  	
18  	@ElementCollection
19  	@CollectionTable(
20  			name="RELATIONEX_BASKET_PRODUCE",
21  			joinColumns=@JoinColumn(name="BASKET_ID"))
22  	@AttributeOverrides({
23  		@AttributeOverride(name="name", column=@Column(name="ITEM_NAME")),
24  		@AttributeOverride(name="color", column=@Column(name="ITEM_COLOR"))
25  	})
26  	private List<Produce> contents;
27  	
28  	@Column(length=16)
29  	private String name;
30  
31  	public int getId() { return id; }
32  
33  	public List<Produce> getContents() {
34  		if (contents == null) { contents = new ArrayList<Produce>(); }
35  		return contents;
36  	}
37  	public void setContents(List<Produce> contents) {
38  		this.contents = contents;
39  	}
40  
41  	public String getName() { return name; }
42  	public void setName(String name) {
43  		this.name = name;
44  	}
45  }