How to make Unidirectional Relationship in EJB 3.0 Entity-Beans (JPA)?
For example Customer know about Order but Order has not any method for Customer. using (@OneTo
Here's how you'd make a unidirectional @OneToMany
relationship using JPA 2.0:
@Entity
public class Customer {
@Id
@Column(name="cust_id")
private long id;
...
@OneToMany
@JoinColumn(name="owner_id", referencedColumnName="cust_id")
private List order;
...
}
@Entity
public class Order {
@Id
@Column(name="order_id")
private long id;
...
}
Relational database:
Customer:
+---------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------+------+-----+---------+-------+
| cust_id | int(11) | NO | PRI | NULL | |
+---------+---------+------+-----+---------+-------+
Order:
+----------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| order_id | int(11) | NO | PRI | NULL | |
| owner_id | int(11) | NO | MUL | NULL | |
+----------+---------+------+-----+---------+-------+