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    * This class provides an example owning entity in a one-to-many, uni-directional relationship 
9    * where the members of the collection are subject to orphanRemoval when they are removed from the 
10   * collection. 
11   */
12  @Entity
13  @Table(name="RELATIONEX_TODOLIST")
14  public class TodoList {
15  	@Id @GeneratedValue
16  	private int id;
17  	
18  	@OneToMany(cascade={CascadeType.PERSIST}
19  			,orphanRemoval=true
20  		)
21  	@JoinColumn
22  	private List<Todo> todos;
23  
24  	public int getId() { return id; }
25  
26  	public List<Todo> getTodos() {
27  		if (todos==null) {
28  			todos = new ArrayList<Todo>();
29  		}
30  		return todos;
31  	}
32  	public void setTodos(List<Todo> todos) {
33  		this.todos = todos;
34  	}
35  }