ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dodo" <j2eed...@gmail.com>
Subject many-to-many relationship practice
Date Sun, 09 Jul 2006 05:52:44 GMT

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 
Mime
View raw message