I think making both join-columns not insertable and not updatable should
work.On the promotion (ownerSide) object

   @JoinTable(name = "promotion_pc", schema="public",
        joinColumns = {...@joincolumn(name = "promotion_id",
referencedColumnName = "id", insertable=false, updatable=false)},
        inverseJoinColumns = {...@joincolumn(name = "pc_id",
referencedColumnName = "id", insertable=false, updatable=false)}
    )
    @ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    private List<MyObject> myObject;



Judes


On Wed, Apr 8, 2009 at 6:02 AM, Pinaki Poddar <[email protected]> wrote:

>
> Hi,
>
> > Is there a way to prohibit direct updates to a perisistent Collection?
>
> What exactly happens if you wrap the list as unmodifiable as follows?
>     @ManyToMany (mappedBy="ownerSide", fetch=FetchType.LAZY,
> cascade=CascadeType.PERSIST)
>    private List<MyPcObject> myPcList;
>
>    List<Promotion> getMyPcList()  {
>        if (myPcList == null)
>            myPcList = new ArrayList<MyPcObject>();
>         return Collections.unmodifiableList(myPcList);
>    }
>
> OpenJPA proxies the collections and it is possible to tune these proxies
> including tracking changes them [1]. But that will involve more work from
> the application.
>
> [1]
> http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_scos_proxy_custom
>
>
> 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
>
>
>
>
>
>
> -----
> Pinaki Poddar                      http://ppoddar.blogspot.com/
>
> http://www.linkedin.com/in/pinakipoddar
> OpenJPA PMC Member/Committer
> JPA Expert Group Member
> --
> View this message in context:
> http://n2.nabble.com/Pattern-for-unmodifiable-Collections-tp2600278p2604302.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
>

Reply via email to