To initialize or not initialize JPA relationship mappings?
问题 In one to many JPA associations is it considered a best practice to initialize relationships to empty collections? For example. @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<>(); } In the above example is it better to define lineItems with a default value of an empty ArrayList or not? What are the pros and cons? 回答1: JPA itself doesn't care