View Javadoc
1   package myorg.relex.one2manybi;
2   
3   import java.math.BigDecimal;
4   
5   import javax.persistence.*;
6   
7   /**
8    * This class provides and example of the many/owning side of a many-to-one, bi-directional 
9    * relationship that is realized using a join-table.
10   */
11  @Entity
12  @Table(name="RELATIONEX_SALEITEM")
13  public class SaleItem {
14  	@Id @GeneratedValue
15  	private int id;
16  	
17  	@ManyToOne(optional=false, fetch=FetchType.LAZY)
18  	@JoinTable(
19  		name="RELATIONEX_SALEITEM_PURCHASE", 
20  		joinColumns=@JoinColumn(name="SALEITEM_ID"),
21  		inverseJoinColumns=@JoinColumn(name="PURCHASE_ID")
22  	)
23  	private Purchase purchase;
24  	
25  	@Column(length=16)
26  	private String name;
27  	@Column(precision=5, scale=2)
28  	private BigDecimal price;
29  	
30  	protected SaleItem() {}
31  	public SaleItem(Purchase purchase) {
32  		this.purchase = purchase;
33  	}
34  
35  	public int getId() { return id; }
36  	
37  	public Purchase getPurchase() { return purchase; }
38  	public void setPurchase(Purchase purchase) {
39  		this.purchase = purchase;
40  	}
41  
42  	public String getName() { return name; }
43  	public void setName(String name) {
44  		this.name = name;
45  	}
46  	
47  	public double getPrice() { return price==null? 0 : price.doubleValue(); }
48  	public void setPrice(double price) {
49  		this.price = new BigDecimal(price);
50  	}
51  }