Monday, March 14, 2011

ManyToOne, OneToMany, ManyToMany

@JoinColumn(name="CUST_ID", nullable=false, updatable=false)
public Customer getCustomer() { return customer; }

@OneToMany(cascade=ALL, mappedBy="customer")
public Set getOrders() { return orders; }

the first is always "me", the second is "the other"

ManyToOne means "there are many of me for one of them" -> hence I have only 1 of them, and he has a Set of me

OneToMany means "there is one of me for many of them" -> hence I have a Set of them

public Set getPhones() { return phones; }

I have a Set of them, and they have a Set of me

No comments: