Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 60842 invoked from network); 8 Oct 2009 10:18:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 8 Oct 2009 10:18:38 -0000 Received: (qmail 25614 invoked by uid 500); 8 Oct 2009 10:18:38 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 25542 invoked by uid 500); 8 Oct 2009 10:18:37 -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 25532 invoked by uid 99); 8 Oct 2009 10:18:37 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2009 10:18:37 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of lists+1214986160035-208411@n2.nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 08 Oct 2009 10:18:27 +0000 Received: from tervel.nabble.com ([192.168.236.150]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1Mvq4U-00023j-Au for users@openjpa.apache.org; Thu, 08 Oct 2009 03:18:06 -0700 Date: Thu, 8 Oct 2009 03:18:06 -0700 (PDT) From: Srinivasan Krishnamoorthy To: users@openjpa.apache.org Message-ID: <1254997086334-3787128.post@n2.nabble.com> In-Reply-To: References: <1254844656906-3775923.post@n2.nabble.com> Subject: Re: Conceptual question on ManyToMany Relation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: srinivasan.krish@live.com X-Virus-Checked: Checked by ClamAV on apache.org Hi Wes, Thanks for suggesting this solution.. I agree thats the best way to=20 model this scenario .. so the one liner I would take is "a big no for any Many-To-Many mappings where the entities can theoretically grow to large numbers"..=20 -Regards, Srinivasan Krishnamoorthy. =20 Wes Wannemacher wrote: >=20 > I have an app where I am modelling users/groups, but instead of > leaving it up to the JPA implementation, I created my own junction > table via an intermediary entity. That way, I just have a one-to-many > mapping from users to the UserGroup entity and a one-to-many from > groups to UserGroup. To make it easier, I added @Transient methods to > get a users' groups and the groups' users. This way I can closely > control the behavior. >=20 > You definitely want to use Lazy fetch groups where ever possible in > this sort of setup because loading one user could conceivably load all > of the data from all of the tables. >=20 > On Tue, Oct 6, 2009 at 11:57 AM, Srinivasan Krishnamoorthy > wrote: >> >> Hi, >> =C2=A0I have difficulty in understanding the JPA implementation of ManyT= oMany >> relation, conceptually. >> Let me try to put forward the question with an example. >> I have a many to many relation between users and groups. >> My use case is, I want to add a user to a group. Ideally, with SQL all >> that >> I would be doing is create a new link in a link table. But with JPA, I >> see >> the following steps to be done. >> >> 1. Get a group object, and add the user to the 'User Set'. (If I have >> 1000 >> users I need to fetch them all). >> 2. Add the group to 'Group Set' of User Object. (Here too, I need to >> fetch >> all the groups, say 100). >> 3. JPA will do a 'merge' to find just the extra link and save it. >> >> My question is, why should I do so much to just add a link? Is there an >> easier way to do this.. or is my understanding wrong.. Can you please >> share >> your thoughts on this? >> >> Also, I am afraid, what will happen if both sides of ManyToMany has huge >> data (theoretically). >> >> (PS: With OneToMany I can work around this issue by modeling the system >> to >> always work from Many side, but dont have an idea for ManyToMany) >> >> Best Regards, >> Srinivasan Krishnamoorthy. >> -- >> View this message in context: >> http://n2.nabble.com/Conceptual-question-on-ManyToMany-Relation-tp377592= 3p3775923.html >> Sent from the OpenJPA Users mailing list archive at Nabble.com. >> >=20 >=20 >=20 > --=20 > Wes Wannemacher >=20 > Head Engineer, WanTii, Inc. > Need Training? Struts, Spring, Maven, Tomcat... > Ask me for a quote! >=20 >=20 --=20 View this message in context: http://n2.nabble.com/Conceptual-question-on-M= anyToMany-Relation-tp3775923p3787128.html Sent from the OpenJPA Users mailing list archive at Nabble.com.