I am trying to provide JPA persistent objects in a framework. If I
return a ManyToMany Collection the user has to understand what side is
the mappedBy owner and be careful to update both sides. There are other
reasons for wanting to restrict updates to OneToMany relations. Is
there a way to prohibit direct updates to a perisistent Collection?
@ManyToMany (mappedBy="ownerSide", fetch=FetchType.LAZY,
cascade=CascadeType.PERSIST)
private List<MyPcObject> myPcList;
List<Promotion> getMyPcList()
{
if (myPcList == null)
myPcList = new ArrayList<MyPcObject>();
return myPcList;
}
I tried wrapping the List in a Collections.unmodifiableList(list) but it
looks like OpenJPA can replace the List with another object so the List
I wrapped becomes stale. (Does that make sense by the way - should I
expect that to happen?)
Any suggestions would be appreciated!
- Paul