Can OpenJPA replace a Collection when it is loaded?
With the code below when the list is initially empty you need to create
a List (ArrayList) so you can add elements to it. When I persisted new
objects on the ManyToOne side and added them to the List that worked.
But the first time the List was loaded it seemed to replace my ArrayList
with the newly loaded data and made an older reference to the ArrayList
stale (no longer updated when more elements were added to myPcList).
This was all in one transaction.
So now I wonder if the initial null List is a special case or if OpenJPA
might replace the Collection anytime it decides to load it again.
Anyone know the answer?
If I don't create an initial ArrayList how can I add elements when the
List is empty?
@OneToMany (mappedBy="ownerSide", fetch=FetchType.LAZY,
cascade=CascadeType.PERSIST)
private List<MyPcObject> myPcList;
List<Promotion> getMyPcList()
{
if (myPcList == null)
myPcList = new ArrayList<MyPcObject>();
return myPcList;
}