Thanks Eric. As I suspect. :)
 
Sam
----- Original Message -----
From: Eric Tan
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 );

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 <[EMAIL PROTECTED]> 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. 
 
   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() );
   where category.getItemsList() simply return the ArrayList of Item.
 
   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
CategorizedItem explicitly by adding CategorizedItem to ArryList of Category?
 
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



Real people. Real questions. Real answers. Share what you know.

Reply via email to