ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dodo" <j2eed...@gmail.com>
Subject Re: many-to-many relationship practice
Date Mon, 10 Jul 2006 10:35:23 GMT
Thanks Eric. As I suspect. :) 

Sam
  ----- Original Message ----- 
  From: Eric Tan 
  To: user-java@ibatis.apache.org 
  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 <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