假设我有两个实体:
@Entity
public class Customer implements Serializable {
...
@OneToMany(cascade=ALL, mappedBy="customer")
public Set<Order> getOrders() {
return orders;
}
...
}
@Entity
public class Order implements Serializable {
...
@ManyToOne
@JoinColumn(name="CUST_ID", nullable=false)
public Customer getCustomer() {
return customer;
}
...
}
然后,我坚持客户实体,之后,参考先前添加的客户的订单实体。当我从数据库中检索此客户并调用 getOrders 时,它返回空集。这是正常行为吗?如果是,当我添加新的订单实体时,我该怎么做才能自动刷新这个集合?