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. :) 

  ----- 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


  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.


  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,
    many-to-many relationship. So I introduced an association class named CategorizedItem

    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


    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




  Real people. Real questions. Real answers. Share what you know.
View raw message