ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "MCCORMICK, Paul" <Paul.McCORM...@doir.wa.gov.au>
Subject RE: How can I reuse a resultMap.
Date Wed, 12 Jul 2006 07:26:04 GMT
That issues is resolved in latest version:
http://issues.apache.org/jira/browse/IBATIS-225

________________________________

From: MCCORMICK, Paul [mailto:Paul.McCORMICK@doir.wa.gov.au] 
Sent: Wednesday, 12 July 2006 3:02 PM
To: user-java@ibatis.apache.org
Subject: How can I reuse a resultMap.




I have a resultMap I use to populate a Name object.  Here is the class
and result map. 
------------------------------------------------------------------------
-------------------------------- 
public class Name { 
    public Integer name_id 
} 

public class CompanyName extends Name { 
        // has may properties 
} 

public class PersonName extends Name { 
        // has may properties 
} 

<resultMap id="NameRM" class="foo.Name"> 
  <result property="name_id" column="NAME_ID"/> 
  <discriminator javaType="java.lang.String" column="NAME_TYPE">        
        <subMap resultMap="CompanyNameRM" value="C"/> 
        <subMap resultMap="PersonNameRM" value="P"/> 
  </discriminator> 
</resultMap> 
------------------------------------------------------------------------
-------------------------------- 

How can I use the above resultMap definition when the Name class is a
property of an object.  The Customer class has a Name as a property.  

------------------------------------------------------------------------
-------------------------------- 
public class Customer { 
        private Integer customerId; 
        private Name name; 
} 

<resultMap id="CustomerRM" class="foo.Customer"> 
  <result property="customerId" column="CUSTOMER_ID"/> 
  
  <!-- This next line does not work.  It expects to set a list of Names
on the Customer object --> 
  <result property="name" resultMap="NameRM"/> 
</resultMap> 


<select id="findCustomers" resultMap="CustomerRM"> 
        select CUSTOMER_ID, NAME_ID, NAME_TYPE, ....    
</select> 
------------------------------------------------------------------------
-------------------------------- 
I can get it to work is I add a List property to the Customer class and
use that instead of the Name property..  E.g 

------------------------------------------------------------------------
-------------------------------- 
public class Customer { 
        private Integer customerId; 
        // private Name name; 
        private List nameList;  
        
        public Name getName() { 
                return (Name)getNameList().get(0); 
        }       
} 
------------------------------------------------------------------------
-------------------------------- 
I don't want to complicate the bean by adding getters and setters that
are only used by Ibatis.  Is there another way to do this?

Thanks, 
Paul 



"DISCLAIMER: This email, including any attachments, is intended only for
use by the addressee(s) and may contain confidential and/or personal
information and may also be the subject of legal privilege. If you are
not the intended recipient, you must not disclose or use the information
contained in it. In this case, please let me know by return email,
delete the message permanently from your system and destroy any copies. 

Before you take any action based upon advice and/or information
contained in this email you should carefully consider the advice and
information and consider obtaining relevant independent advice.
	

Mime
View raw message