ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dan Forward <dan-nab...@forwardhome.com>
Subject Re: Mapping a Complex Object
Date Wed, 30 Dec 2009 18:39:13 GMT

Guy Rouillier-2 wrote:
> You don't say what version of iBATIS you are using.  Since you say you 
> are new, so I'm guessing you are using iBATIS 3.  You shouldn't need any 
> callbacks; from your description, a simple ResultMap should suffice. 
> Take a look at the iBATIS 3 User Guide, particularly the section titled 
> Advanced Result Mapping.  The example mirrors what you are attempting, 
> so hopefully you will be able to identify what you need to do. 
> Specifically, you can map multiple name columns to a Name object using 
> an association.  Though in reality, since only people have names, I 
> don't really understand the need to have a separate Name object type.
> Write back with specific questions after you've digested the
> documentation.

Thank you, Guy. You are right, I am using iBATIS 3. It looks like iBATIS 3
uses the TypeHandler interface instead of the TypeHandlerCallBack interface
I saw in some online examples. Still, this only works for single-column
objects, like the IDs.

The reason for the special Name object is to make it easier to display and
sort names, e.g. "Last, First Middle Suffix", "First Middle Last, Suffix",
or "First M. Last".

I have other scenarios like this, such as storing dates with millisecond
precision. MySQL has only second precision using timestamp columns, so I
have to store the millisecond portion in a separate column and use both
columns to reconstruct the Date.

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?

I will try implementing it this way, but would still appreciate any insight
someone may have who has done a one-to-one, same-table mapping before.
View this message in context: http://old.nabble.com/Mapping-a-Complex-Object-tp26961927p26970785.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.

To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org

View raw message