On 12/29/2009 6:22 PM, Dan Forward wrote:

I am new to iBATIS and I am having difficulty mapping our User object, which
consists of several custom objects, some of which span multiple columns in
the database. However, all the data for the user is stored in one table.

These are the properties of my User object:

private UserID id;
private Name name;
private Gender gender;
private EmailAddress email;
private TelephoneNumber phone;
private LocalDate birthDate;
private Hash passwordHash;
private StaticFileID avatarID;
private OrganizationID organizationID;
private int version;

The database schema looks like this:

create table user (
     id char(22) not null,
     first_name varchar(255),
     middle_name varchar(255),
     last_name varchar(255),
     suffix varchar(255),
     gender enum('Male', 'Female'),
     email varchar(255),
     phone char(14),
     birth_date date,
     password_hash char(22),
     avatar_id char(22),
     organization_id char(22),
     version int(11),
     primary key (id),
     unique key (email)
)

I think I can handle the single-column values by implementing
TypeHandlerCallback, but I am baffled how to handle the Name object, which
consists of four columns. Any help would be very much appreciated.

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.

--
Guy Rouillier

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

Reply via email to