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 Sat, 02 Jan 2010 22:51:49 GMT

Thank you, Guy, you have been a big help!

This is what I came up with. It works, but not as well as I had hoped.

<resultMap type="User" id="userMap">
		<idArg column="id" javaType="UserID" typeHandler="UserIDHandler"/>
		<arg column="gender" javaType="Gender" typeHandler="GenderHandler"/>
		<arg column="email" javaType="EmailAddress"
		<arg column="phone" javaType="TelephoneNumber"
		<arg column="birth_date" javaType="LocalDate"
		<arg column="password_hash" javaType="SHA1" typeHandler="SHA1Handler"/>
		<arg column="avatar_id" javaType="StaticFileID"
		<arg column="organization_id" javaType="OrganizationID"
		<arg column="version" javaType="int"/>
	<association property="name" javaType="Name">
			<arg column="first_name" javaType="String"/>
			<arg column="middle_name" javaType="String"/>
			<arg column="last_name" javaType="String"/>
			<arg column="suffix" javaType="String"/>

I was surprised that I had to specify the javaType for every parameter.
Otherwise, iBATIS treated everything as an Object and could not find a
corresponding constructor. I then discovered that iBATIS was looking for an
Integer argument for the version even though I specified the javaType to be
an int. Finally, I had to remove name from the constructor since constructor
tags do not support child association tags.

As a side note, I try to follow the recommendation by Joshua Bloch in
Effective Java to use static factory methods instead of constructors, so I
only have private constructors. I used DefaultObjectFactory as a model to
create my own ObjectFactory that first looks for a matching static factory
method before looking for a constructor.

One of the reasons I chose iBATIS was that Hibernate put too many
constraints on my domain model. It isn't really a POJO if you say it has to
have a public constructor, an empty constructor, and setters for every
property. iBATIS is less strict, but still has some hoops to jump through.
Wouldn't it be nice to have a persistence layer that transparently
accommodated the domain model? What if I wanted to use a separate Factory
class to create my User objects?

I am willing to help make these changes to iBATIS if I am not missing
something that may already be there.


Dan Forward
View this message in context: http://old.nabble.com/Mapping-a-Complex-Object-tp26961927p26997280.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