View Javadoc
1   package myorg.relex.one2manybi;
2   
3   import java.util.ArrayList;
4   import java.util.List;
5   
6   import javax.persistence.*;
7   /**
8    * This class provides an example of the one/parent side of a one-to-many, bi-directional relationship
9    * that will be realized through a foreign key from the many/child side of the relationship. Being the 
10   * one side of the one-to-many relationship, this class must implement the inverse side.
11   */
12  @Entity
13  @Table(name="RELATIONEX_BORROWER")
14  public class Borrower {
15      @Id @GeneratedValue
16      private int id;
17      
18      @OneToMany(
19      		mappedBy="borrower"
20      		, cascade={CascadeType.PERSIST, CascadeType.DETACH, CascadeType.REMOVE}
21      		, orphanRemoval=true
22      		, fetch=FetchType.EAGER
23      		)
24      private List<Loan> loans;
25      
26      @Column(length=12)
27      private String name;
28  
29  	public int getId() { return id; }
30  
31  	public List<Loan> getLoans() {
32  		if (loans == null) {
33  			loans = new ArrayList<Loan>();
34  		}
35  		return loans;
36  	}
37  
38  	public void setLoans(List<Loan> loans) {
39  		this.loans = loans;
40  	}
41  
42  	public String getName() { return name; }
43  	public void setName(String name) {
44  		this.name = name;
45  	}
46  }