ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Paul.Smi...@barclayscapital.com>
Subject RE: Struggling to load a complex property from a secondary table (a 1:N problem)
Date Fri, 06 Jan 2006 13:03:36 GMT
Thanks Niels, that works perfectly. I had completely mis-understood the
use of the column attirbute when a select is present!

Now, a couple of slightly more tricky questions!

1. How can I change the Collection implementation that the results get
mapped into? By default it's a List but I would prefer to use a Set. I
can achieve this by adding an overloaded set method that converts a List
into a Set onto my business object but can I do it in the mapping

2. I am aware that I can register a Custom Type Handler for complex
properties, but can I explicitly tell iBatis to use a specific custom
type handler for a given property? The scenario is this, I have two
legacy database columns that use integers to describe boolean
properties. One regards null as true, the other as false (I know, I
know, but it's a legacy database that can't be changed!) so I would like
to use different custom type handlers for each column despite the fact
that they both map from int to boolean.


Paul Smith

-----Original Message-----
From: Niels Beekman [mailto:n.beekman@wis.nl] 
Sent: 06 January 2006 12:19
To: user-java@ibatis.apache.org
Subject: RE: Struggling to load a complex property from a secondary
table (a 1:N problem)


You should change the resultmap, you have to specify the columnName of
the value you would like to pass to "findPermissionByUserId":

<resultMap id="UserResultMap" class="User">
	<result property="userId" column="UserId"/>
	<result property="permissions" column="UserId"
select="findPermissionByUserId"/> </resultMap>

Hope this helps,


-----Original Message-----
From: Paul.Smith3@barclayscapital.com
Sent: vrijdag 6 januari 2006 13:16
To: user-java@ibatis.apache.org
Subject: Struggling to load a complex property from a secondary table (a
1:N problem)


I am struggling with the following scenario. Basically I'm trying to get
iBatis to load a complex property (a list of int) from a secondary

I have two tables, User and Permission. The pk of the User table
(UserId) is a fk in the Permission table, and there are many Permission
rows for each UserId. I am trying to get iBatis to perform the select
from the Permission table whenever a select is performed on the User
table, but I always get a 'Invalid column name' from the underlying jdbc
driver. I can't work out what query iBatis is trying to perform that is
yielding this error.

My SqlMap is setup so that the permissions property (a java.util.List of
java.lang.Integer) of the User resultMap is as follows:

<resultMap id="UserResultMap" class="User">
	<result property="userId" column="UserId"/>
	<result property="permissions" column="permissionId"
select="findPermissionByUserId"/> </resultMap>

The "findPermissionByUserId" select is defined as:

<select id="findPermissionByUserId" parameterClass="int"
	select PermissionId as permissionId from Permissions where
UserId = #value# </select>

The select is initaited from a "findUserById" select which is defined

<select id="findUserById" parameterClass="int"
	select * from User where UserId = #value#

Any help is greatly appreciated.


Paul Smith

For more information about Barclays Capital, please
visit our web site at http://www.barcap.com.

Internet communications are not secure and therefore the Barclays 
Group does not accept legal responsibility for the contents of this 
message.  Although the Barclays Group operates anti-virus programmes, 
it does not accept responsibility for any damage whatsoever that is 
caused by viruses being passed.  Any views or opinions presented are 
solely those of the author and do not necessarily represent those of the

Barclays Group.  Replies to this email may be monitored by the Barclays 
Group for operational or business reasons.


View raw message