Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 88899 invoked from network); 7 Apr 2009 17:25:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 7 Apr 2009 17:25:52 -0000 Received: (qmail 93738 invoked by uid 500); 7 Apr 2009 17:25:51 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 93667 invoked by uid 500); 7 Apr 2009 17:25:51 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 93657 invoked by uid 99); 7 Apr 2009 17:25:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 17:25:51 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [69.49.111.76] (HELO mail176c2.megamailservers.com) (69.49.111.76) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2009 17:25:43 +0000 X-Authenticated-User: paul.copelandz.com Received: from [127.0.0.1] (ellen.pc.ashlandfiber.net [66.241.90.23] (may be forged)) (authenticated bits=0) by mail176c2.megamailservers.com (8.13.6/8.13.1) with ESMTP id n37HPHDV024849 for ; Tue, 7 Apr 2009 13:25:20 -0400 Message-ID: <49DB8C7D.1060203@jotobjects.com> Date: Tue, 07 Apr 2009 10:25:17 -0700 From: Paul Copeland Organization: JOT Object Technologies User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: users@openjpa.apache.org Subject: Pattern for unmodifiable Collections Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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 myPcList; List getMyPcList() { if (myPcList == null) myPcList = new ArrayList(); 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