From users-return-5543-apmail-openjpa-users-archive=openjpa.apache.org@openjpa.apache.org Fri Sep 11 07:26:06 2009 Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 49020 invoked from network); 11 Sep 2009 07:26:03 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Sep 2009 07:26:03 -0000 Received: (qmail 86542 invoked by uid 500); 11 Sep 2009 07:26:03 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 86480 invoked by uid 500); 11 Sep 2009 07:26:02 -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 86470 invoked by uid 99); 11 Sep 2009 07:26:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Sep 2009 07:26:02 +0000 X-ASF-Spam-Status: No, hits=3.4 required=10.0 tests=HTML_MESSAGE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [209.85.132.245] (HELO an-out-0708.google.com) (209.85.132.245) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Sep 2009 07:25:50 +0000 Received: by an-out-0708.google.com with SMTP id b38so288051ana.18 for ; Fri, 11 Sep 2009 00:25:29 -0700 (PDT) Received: by 10.101.95.6 with SMTP id x6mr2738233anl.108.1252653929489; Fri, 11 Sep 2009 00:25:29 -0700 (PDT) Received: from brevsnb004 ([222.124.191.68]) by mx.google.com with ESMTPS id 21sm1311383yxe.13.2009.09.11.00.25.24 (version=SSLv3 cipher=RC4-MD5); Fri, 11 Sep 2009 00:25:28 -0700 (PDT) Reply-To: From: "C N Davies" To: Subject: Linking Entities Creating too many cascading queries Date: Fri, 11 Sep 2009 15:25:15 +0800 Organization: C N Davies Pty Ltd Message-ID: <003801ca32b1$07606b00$16214100$@com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0039_01CA32F4.1583AB00" X-Mailer: Microsoft Office Outlook 12.0 thread-index: AcoysQGbdM98KmCETYyY7E6dTrSEPQ== Content-Language: en-au X-Virus-Checked: Checked by ClamAV on apache.org ------=_NextPart_000_0039_01CA32F4.1583AB00 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi, I have a number of entities that are linked so I set there their cascade type to REFRESH since each of the entities will have a ManyToOne relationship to the other entities, for example I have 3 entities, User, Address, Country Where more than one user can share the same Address and each Address will be associated with a Country entity. So my definition in short is like this: User Entity: @ManyToOne (cascade={CascadeType.REFRESH}) private Address address; Address Entity: @ManyToOne (cascade={CascadeType.REFRESH}) private Country country; Hope that makes sense. What I find is that when I persist/merge a user entity, it also generates SQL that updates the linked Address entity which in turn also generates SQL that updates the Country entity. This seems like a load of redundant table updates when I am only linking the entities together not updating any fields in the Address or Country entities.. How do others usually achieve this? Do you not use the cascade functionality at all and just code the getters and setters manually? It seems like this is the only other way I can achieve the desired behaviour. As my entity relationships have become more complex, I am now facing stack overflows as there may be reverse relationships between entities. The advantage of using CascadeType.REFRESH is that OpenJPA will create all the join tables for me and I don't have to write any code to do this, also the getters and setters are very simple and I can use lazy loading if required. But it seems that all these redundant table updates causes a significant performance hit. So I want to know if I am taking the correct approach or there is a better way. Thanks for any advice. Chris ------=_NextPart_000_0039_01CA32F4.1583AB00--