ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rick" <ricks_mailingli...@arc-mind.com>
Subject Working with composite objects and the syntax phoneNumbers[0].areaCode
Date Thu, 29 Jun 2006 00:22:04 GMT
 

I have a result set that has phone1, phone2, phone3, phone4, areaCode1,
areaCode2, areaCode3, areaCode4.

 

I want to map these to composite objects.

 

I.e., Employee has Contacts, Contact has phone numbers, phone number consist
of number and area code.

 

When I try to map this, I get this error:

 

 

Caused by: 

com.ibatis.common.beans.ProbeException: There is no WRITEABLE property named
'phoneNumbers[0]' in class 'qcom.cas.mysourcej.poc.model.Contact'

            at
com.ibatis.common.beans.ClassInfo.getSetterType(ClassInfo.java:174)

            at
com.ibatis.common.beans.GenericProbe.getClassPropertyTypeForSetter(GenericPr
obe.java:250)

            at
com.ibatis.common.beans.GenericProbe.getPropertyTypeForSetter(GenericProbe.j
ava:137)

            at
com.ibatis.sqlmap.engine.builder.xml.BaseParser.resolveTypeHandler(BaseParse
r.java:68)

            at
com.ibatis.sqlmap.engine.builder.xml.SqlMapParser$15.process(SqlMapParser.ja
va:403)

            .

 

Here is my mapping file:

 

      <resultMap id="employee" class="qcom.cas.mysourcej.poc.model.Employee"
groupBy="emplid">

            <result property="emplid" column="emplid" />

            <result property="name" column="name" />

            <result property="contacts" resultMap="employee.contacts"/>

      </resultMap>

 

      <resultMap id="contacts" class="qcom.cas.mysourcej.poc.model.Contact">

            <result property="name" column="contact_name"/>

            <result property="primaryContact" column="primary_contact"

 
typeHandler="qcom.cas.commons.ibatis.typehandler.StringBooleanTypeHandler"
/>

            <result property="relationship" column="relation"/>

            <result property="phoneNumbers[0].number" column="phone1"/>

            <result property="phoneNumbers[1].number" column="phone2"/>

            <result property="phoneNumbers[2].number" column="phone3"/>

            <result property="phoneNumbers[3].number" column="phone4"/>

            <result property="phoneNumbers[0].areaCode" column="areaCode1"/>

            <result property="phoneNumbers[1].areaCode" column="areaCode2"/>

            <result property="phoneNumbers[2].areaCode" column="areaCode3"/>

            <result property="phoneNumbers[3].areaCode" column="areaCode4"/>

      </resultMap>

 

Page 50 of the iBatis user manual states that the syntax
phoneNumbers[3].areaCode  is possible for a mapping.

 

I googled this as follows: http://www.google.com/search?hl=en
<http://www.google.com/search?hl=en&lr=lang_en&newwindow=1&rls=GGLG%2CGGLG%3
A2006-17%2CGGLG%3Aen&q=%22There+is+no+WRITEABLE+property+named%22+ProbeExcep
tion>
&lr=lang_en&newwindow=1&rls=GGLG%2CGGLG%3A2006-17%2CGGLG%3Aen&q=%22There+is+
no+WRITEABLE+property+named%22+ProbeException

 

I did notice that there was a similar issue at:
http://www.mail-archive.com/dev@ibatis.apache.org/msg00521.html

 

It seems this syntax may not be supported even though the documents elude
that it is on page 50. How do you do this w/o the above syntax?

 

Here is the object model for reference..

 

package qcom.cas.mysourcej.poc.model;

 

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

 

public class Contact implements Serializable {

      private List phoneNumbers = new ArrayList();

 

 

      private String name;

      private boolean primaryContact;

      private String relationship = "Spouse";

 

      public Contact() {

            phoneNumbers.add(new Phone());

            phoneNumbers.add(new Phone());

            phoneNumbers.add(new Phone());

            phoneNumbers.add(new Phone());

      }

 

 

 

      public Contact(String name) {

            super();

            this.name = name;

      }

 

      public Contact(String name, Phone phone) {

            super();

            this.name = name;

            phoneNumbers.add(phone);

      }

 

      public Contact(String name, Phone phone, String relationship) {

            this(name, phone);

            this.relationship = relationship;

      }

 

      public boolean isPrimaryContact() {

            return primaryContact;

      }

      public void setPrimaryContact(boolean primaryContact) {

            this.primaryContact = primaryContact;

      }

      public String getName() {

            return name;

      }

      public void setName(String name) {

            this.name = name;

      }

      public List getPhoneNumbers() {

            return phoneNumbers;

      }

      public void setPhoneNumbers(List phoneNumbers) {

            this.phoneNumbers = phoneNumbers;

      }

 

 

 

      public String getRelationship() {

            return relationship;

      }

 

 

 

      public void setRelationship(String relationship) {

            this.relationship = relationship;

      }

}

 

package qcom.cas.mysourcej.poc.model;

 

import java.io.Serializable;

import java.util.ArrayList;

import java.util.List;

 

public class Employee implements Serializable{

      private String emplid;

      private List directReports = new ArrayList();

      private List contacts = new ArrayList();

      private Employee boss;

      private String name;

 

      public Employee () {

 

      }

 

      public Employee(Employee boss, String name) {

            super();

            this.boss = boss;

            this.name = name;

            if (this.boss !=null) {

                  boss.addEmployee(this);

            }

      }

 

      public Employee(Employee boss, String name, Contact contact) {

            this(boss, name);

            contacts.add(contact);

      }

 

      public void addEmployee(Employee employee) {

            employee.setBoss(this);

            this.directReports.add(employee);

      }

      public String getName() {

            return name;

      }

      public void setName(String name) {

            this.name = name;

      }

      public List getDirectReports() {

            return directReports;

      }

      public void setDirectReports(List directReports) {

            this.directReports = directReports;

      }

      public Employee getBoss() {

            return boss;

      }

      public void setBoss(Employee boss) {

            this.boss = boss;

      }

      public List getContacts() {

            return contacts;

      }

      public void setContacts(List contacts) {

            this.contacts = contacts;

      }

 

      public String toString() {

            return name;

      }

 

      public String getEmplid() {

            return emplid;

      }

 

      public void setEmplid(String emplid) {

            this.emplid = emplid;

      }

}

 

package qcom.cas.mysourcej.poc.model;

 

import java.io.Serializable;

 

public class Phone implements Serializable{

      private String areaCode;

      private String number;

      private boolean uS=true;

 

      public Phone () {

 

      }

 

      public Phone(String areaCode, String number, boolean us) {

            super();

            this.areaCode = areaCode;

            this.number = number;

            uS = us;

      }

 

      public String getAreaCode() {

            return areaCode;

      }

      public void setAreaCode(String areaCode) {

            this.areaCode = areaCode;

      }

      public String getNumber() {

            return number;

      }

      public void setNumber(String number) {

            this.number = number;

      }

      public boolean isUS() {

            return uS;

      }

      public void setUS(boolean us) {

            uS = us;

      }

 

      public String toString() {

            if (uS) {

                  return this.areaCode + "\\"  + this.number;

            } else {

                  return this.areaCode + "-"  + this.number;

            }

      }

}

 

 

 


Mime
View raw message