On 12/30/2009 1:39 PM, Dan Forward wrote:
The Association tag looks promising, but I am confused by the column attribute. It wants an ID for the Name, but Names are not first-class data objects and have no ID. The Association tag seems to be intended for a one-to-many or many-to-many join. I could query the UserID twice with different aliases and use one for the Name object, but it feels like a hack. Will iBATIS then cache Name objects independent of User objects? I really do not want them cached separately. It is a one-to-one mapping with a User. Is this an uncommon scenario?
Associations are made for 1-to-1 relationships. 1-to-many are handled with collections. So, using a Name object via association would appear to work well here since you want to keep the name fields in a separate object type. You don't need to retrieve any columns twice. If necessary, you can repeat a single database column in a result map, and do different things with each of the multiple occurrences. In my case, or example, I have a site_id column that I map twice; once I store the retrieved value as is, and in the second occurrence I map it to a Site object via an association.
However, from your description, you do not want to store an ID with the Name object, and you do not have to do so. If you reread the documentation, it states that you can leave out the ID column. It cautions about a performance penalty, but that warning is based on retrieving additional results from the database via a separate SELECT. Since you already have all your results from the original SELECT, you should not incur a performance penalty.
-- Guy Rouillier --------------------------------------------------------------------- To unsubscribe, e-mail: user-java-unsubscr...@ibatis.apache.org For additional commands, e-mail: user-java-h...@ibatis.apache.org