ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Tan <erictan...@yahoo.com.sg>
Subject Re: many-to-many relationship practice
Date Mon, 10 Jul 2006 08:45:24 GMT
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 <j2eedodo@gmail.com> 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.
Mime
View raw message