ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Simpson, Michael" <MSimp...@ATPCO.NET>
Subject RE: How do I resultmap a composite member variable?
Date Thu, 22 Dec 2005 21:50:58 GMT
Thanks!

________________________________

From: Nathan.Maves@Sun.COM [mailto:Nathan.Maves@Sun.COM] 
Sent: Thursday, December 22, 2005 4:51 PM
To: user-java@ibatis.apache.org
Subject: Re: How do I resultmap a composite member variable?


It is easier then you think!


<resultMap id="personmap" class="Person">
        <result property="SSN" column="ssn"/>
        <result property="name.firstName" column="FNAME"/>
<result property="name.lastName" column="LNAME"/>
</resultMap>




I think you have to have have a no argument constructor for you
Name.class


should work!




On Dec 22, 2005, at 2:31 PM, Simpson, Michael wrote:


	Assume I have something like the following:
	 
	public class Name {
	    String firstName;
	    String lastName;
	    // getter & setter for both
	}
	 
	 
	public class Person {
	    String ssn;
	    Name name;
	    // getter & setter for both
	}
	 
	And assume I have a table PERSON with columns SSN, FNAME, LNAME
	 
	I want to map creating Person objects but I get hung up with the
"name" member object that is composed of two of the columns in the
table. I'm writing something like this but it does not work:
	 
	    <resultMap id="namemap" class="Name">
	        <result property="firstName" column="FNAME"/>
	        <result property="firstName" column="LNAME">
	    </resultMap>
	 
	    <resultMap id="personmap" class="Person">
	        <result property="SSN" column="ssn"/>
	        <result property="name" column="{FNAME, LNAME}"
resultMap="namemap"/>
	 
	The last line is where I am stuck. I don't want to reference a
statement since I already have the field I want. How do I get the two
columns to be composed into the "name" property?
	 
	Thanks.
	 
	




Mime
View raw message