ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ingmar Lötzsch <iloetz...@asci-systemhaus.de>
Subject Re: [resultMap] related objects
Date Thu, 02 Apr 2009 12:21:02 GMT
> Do I have to use TypeHandler? But how?

You don't need a custom TypeHandler. But perhaps you have to provide
more information.

What are the column names of the tables "companies" and "adresses"?

Your first message shows that they are different from the class properties.

Which packages contain the classes Company and Address?

Did you declare aliases for these classes?

Which files contain the resultMap elements?

Which packages contain these files?

How looks your <select> element?

How do you invoke the SQL-Statement?

What exceptions do you get?

What DBMS do you use?

Assuming that you have tables

companies
(
	id int,
	name text,
	adress_id int
)

adresses
(
	address_id int,
	street text
)

Than you can write basically

<resultMap id="address-result" class="Address">
	<result property="addressId" column="adress_id" />
	<result property="street" column="street" />
</resultMap>

<resultMap id="comp-result" class="Company">
	<result property="id" column="id" />
	<result property="name" column="name" />
	<result property="address" resultMap="address-result" />
</resultMap>

<select id="selectAllCompanies" resultMap="comp-result">
	SELECT
		c.id,
		c.name,
		a.adress_id,
		a.street
	FROM companies c, addresses a
	WHERE a.address_id = c.address_id
</select>

In your DAO

List<Company> list = sqlMapClient.queryForList("selectAllCompanies");

Ingmar

Mime
View raw message