【发布时间】:2014-01-09 23:53:57
【问题描述】:
在一对多 JPA 关联中,将关系初始化为空集合是否被认为是最佳实践?例如。
@Entity
public class Order {
@Id
private Integer id;
// should the line items be initialized with an empty array list or not?
@OneToMany(mappedBy="order")
List<LineItem> lineItems = new ArrayList<>();
}
在上面的例子中,用空ArrayList 的默认值定义lineItems 是否更好?有什么好处和坏处?
【问题讨论】:
标签: java hibernate jpa eclipselink openjpa