Return-Path: Delivered-To: apmail-ibatis-user-java-archive@www.apache.org Received: (qmail 14254 invoked from network); 10 Jul 2006 10:35:41 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Jul 2006 10:35:41 -0000 Received: (qmail 44424 invoked by uid 500); 10 Jul 2006 10:35:38 -0000 Delivered-To: apmail-ibatis-user-java-archive@ibatis.apache.org Received: (qmail 44412 invoked by uid 500); 10 Jul 2006 10:35:38 -0000 Mailing-List: contact user-java-help@ibatis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user-java@ibatis.apache.org Delivered-To: mailing list user-java@ibatis.apache.org Received: (qmail 44401 invoked by uid 99); 10 Jul 2006 10:35:38 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2006 03:35:38 -0700 X-ASF-Spam-Status: No, hits=0.5 required=10.0 tests=DNS_FROM_RFC_ABUSE,HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: domain of j2eedodo@gmail.com designates 64.233.166.178 as permitted sender) Received: from [64.233.166.178] (HELO py-out-1112.google.com) (64.233.166.178) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Jul 2006 03:35:37 -0700 Received: by py-out-1112.google.com with SMTP id o67so1222305pye for ; Mon, 10 Jul 2006 03:35:16 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:from:to:references:subject:date:mime-version:content-type:x-priority:x-msmail-priority:x-mailer:x-mimeole; b=roQITzlwdRdN9ykPCJjq+S7Y7mUNminLTiWbT24McALUXuUgitju3K7fzxrCjCejjZOMqltreYlOg1JNIDNHkRxo+gzgblbo0Jttl+PG8wdmI3vXS0/SCfBlTNnyorI57AlOoeYtcPdQB5KsqcsLKGDaiBaMiVezQj3JeAptkiw= Received: by 10.35.132.13 with SMTP id j13mr3014940pyn; Mon, 10 Jul 2006 03:35:16 -0700 (PDT) Received: from spring ( [60.234.165.68]) by mx.gmail.com with ESMTP id m39sm383128pye.2006.07.10.03.35.12; Mon, 10 Jul 2006 03:35:14 -0700 (PDT) Message-ID: <001f01c6a40c$8ea7c400$0401a8c0@spring> From: "Dodo" To: References: <20060710084524.46204.qmail@web33306.mail.mud.yahoo.com> Subject: Re: many-to-many relationship practice Date: Mon, 10 Jul 2006 22:35:23 +1200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_001C_01C6A471.21D9A810" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2869 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. ------=_NextPart_000_001C_01C6A471.21D9A810 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks Eric. As I suspect. :)=20 Sam ----- Original Message -----=20 From: Eric Tan=20 To: user-java@ibatis.apache.org=20 Sent: Monday, July 10, 2006 8:45 PM Subject: Re: many-to-many relationship practice Hi, There should not be any association class in your domain model. Your = domain model should be independent from your data model. Your code would look like your second option, but your might use the = entire category object as input: Add item to category... CategoryDao.saveCategory( category );=20 Then create insert statements in the sql-map-config.xml to insert the = relevant rows in the category and associative tables. Call those = statements from your DAO.saveCategory(). You will have to take care of = the foreign key constraints. -Eric Dodo wrote: Hi ibatiser, Just a simple question on the general practice of implementing = many-to-many relationship in ibatis. I have a category object that can have many item, an item can belong = to many category, hence many-to-many relationship. So I introduced an association class = named CategorizedItem between them. Now what's the standard or prefered way of implementing this as = below, 1. Add CategorizedItem to ArryList of Category, then call = CategoryDao.saveCategory( category.getCategorizedItems() ); where category.getCategorizedItems() simply return the ArrayList = of CategorizedItem. =20 Within CategoryDao.saveCategory(), CategorizedItem and Item will = then be saved to database or 2. Add Item to ArryList of Category, then call = CategoryDao.saveCategory( category.getItemsList() );=20 where category.getItemsList() simply return the ArrayList of = Item.=20 Within CategoryDao.saveCategory(), CategorizedItem and Item will = be saved to database Currently I am going with approach 1. but I suddenly think why shud = user handle or know about the association class=20 CategorizedItem explicitly by adding CategorizedItem to ArryList of = Category?=20 I can't help thinking maybe I am making a big mistake in my design = and shud go with approach 2 instead. Any advice wud be greatly appreciated Thanks, Samuel=20 -------------------------------------------------------------------------= ----- Real people. Real questions. Real answers. Share what you know. ------=_NextPart_000_001C_01C6A471.21D9A810 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Thanks Eric. As I suspect. :) =
 
Sam
----- Original Message -----
From:=20 Eric=20 Tan
Sent: Monday, July 10, 2006 = 8:45 PM
Subject: Re: many-to-many = relationship=20 practice

Hi,

There should not be any association class in = your=20 domain model. Your domain model should be independent from your data=20 model.

Your code would look like your second option, but your = might use=20 the entire category object as input:

Add item to=20 category...
CategoryDao.saveCategory( category );

Then = create=20 insert statements in the sql-map-config.xml to insert the relevant = rows in the=20 category and associative tables. Call those statements from your=20 DAO.saveCategory(). You will have to take care of the foreign key=20 constraints.

-Eric


Dodo=20 <j2eedodo@gmail.com> wrote:
 
Hi ibatiser,
 
Just a simple question on the = general practice=20 of implementing many-to-many relationship in ibatis.
 
I have a category object that can = have many=20 item, an item can belong to many category, hence
many-to-many relationship. So I = introduced an=20 association class named CategorizedItem between
them.
 
 
Now what's the standard or prefered = way of=20 implementing this as below,
 
 
1. Add CategorizedItem to ArryList = of Category,=20 then call CategoryDao.saveCategory( category.getCategorizedItems()=20 );
   where=20 category.getCategorizedItems()  simply return the ArrayList of=20 CategorizedItem. 
 
  =20 Within CategoryDao.saveCategory(), CategorizedItem and Item = will then=20 be saved to database
 
or
 
2. Add Item to ArryList of = Category, then call=20 CategoryDao.saveCategory( category.getItemsList() );=20
   where = category.getItemsList()=20 simply return the ArrayList of Item.
 
  =20 Within CategoryDao.saveCategory(), CategorizedItem and = Item will=20 be saved to database
 
 
Currently I am going with approach 1. but I suddenly think why = shud=20 user handle or know about the association class
CategorizedItem explicitly by adding CategorizedItem to = ArryList of=20 Category?
 
I can't help thinking maybe I am making a big mistake in = my design=20 and shud go with approach 2 instead.
 
Any advice wud be greatly appreciated
 
Thanks,
 
Samuel



Real people. Real = questions.=20 Real answers. Share what you=20 know. ------=_NextPart_000_001C_01C6A471.21D9A810--