You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Paul Benedict <pb...@apache.org> on 2006/12/27 22:55:17 UTC

ResultMaps for collections of java.lang types (including enum)

I need some help, and the answer I couldn't find in the current sqlmap 
user guide.

I wrote a query which returns a user and its associated roles. The 
resultMap looks like this:

<resultMap id="userMap" class="User" groupBy="id">
   <result property="id" column="u_id" />
   <result property="roles" column="ur_id" />
</resultMap>

As you can see, I am grouping by "id" which means I should be collecting 
all my roles in property "roles" which is a List<Role>. I already have a 
type handler setup to translate the long into the enum/class, but it's 
not working yet.

While I am using Java 5, this problem is not (I don't think) a Java 5 
problem. I've seen many examples of using the @resultMap attribute on a 
collection to construct the objects to avoid N+1 selects. But what about 
just plain old Java types or enums? How do I map an inner collection of 
Long or String? I don't think it makes sense to use @resultMap because 
there are no Java bean properties to a Long or a String (and in my case 
an enum).

Thanks!!
Paul