ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Maves <Nathan.Ma...@Sun.COM>
Subject Re: sql joins in ibatis
Date Thu, 05 Jan 2006 17:16:09 GMT
Where to start.....

ClassNotFound is a java error.  You have either misspelled you class  
name and or package.  Check that you full class name including  
package is correct.

The second problem that I see is in your result map.  You specify  
dept.name when there is no property named that in your Dept.class.   
You have deptName so your result map should be dept.deptName.

Nathan

On Jan 5, 2006, at 9:47 AM, radha rukmani wrote:

> Hi
>
> Can you please give more elaborate explanation.
>
> I changed person.java to look like
>
> public class Person
> {
>   private int id;
>   private String firstName;
>   private String lastName;
>   private Date birthDate;
>   private double weightInKilograms;
>   private double heightInMeters;
>   private int deptNumber;
>   private Dept dept;
>
>   public int getId()
>   {
>    return id;
>   }
>
>   public void setId(int id)
>   {
>    this.id = id;
>   }
>   public String getFirstName()
>   {
>    return firstName;
>   }
>
>   public void setFirstName(String firstName)
>   {
>    this.firstName = firstName;
>   }
>   public String getLastName()
>   {
>    return lastName;
>   }
>
>   public void setLastName(String lastName)
>   {
>    this.lastName = lastName;
>   }
>
>   public Date getBirthDate()
>   {
>    return birthDate;
>   }
>
>   public void setBirthDate(Date birthDate)
>   {
>    this.birthDate = birthDate;
>   }
>   public double getWeightInKilograms()
>   {
>    return weightInKilograms;
>   }
>
>   public void setWeightInKilograms(double weightInKilograms)
>   {
>    this.weightInKilograms = weightInKilograms;
>    ;}
>   public double getHeightInMeters()
>   {
>    return heightInMeters;
>   }
>
>   public void setHeightInMeters(double heightInMeters)
>   {
>    this.heightInMeters = heightInMeters;
>   }
>   public int getDeptNumber()
>   {
>    return deptNumber;
>   }
>
>   public void setDeptNumber(int deptNumber)
>   {
>    this.deptNumber = deptNumber;
>   }
>
>   public void setDeptName(String deptName)
>   {
>    this.dept.setDeptName(deptName);
>   }
>   public String getDeptName()
>   {
>    return dept.getDeptName();
>   }
>   public void setDeptId(int deptId)
>   {
>    this.dept.setDeptId(deptId);
>   }
>
>   public int getDeptId()
>   {
>    return dept.getDeptId();
>   }
> }
>
> and Dept.java is,
> public class Dept
> {
>   private int deptId;
>   private String deptName;
>
>   public int getDeptId()
>   {
>    return deptId;
>   }
>
>   public void setDeptId(int deptId)
>   {
>    this.deptId = deptId;
>   }
>   public String getDeptName()
>   {
>    return deptName;
>   }
>
>   public void setDeptName(String deptName)
>   {
>    this.deptName = deptName;
>   }
> }
> and the Person.xml is like
>
> <typeAlias alias="dept" type="com.pfizer.geca.batchProcess.Dept"/>
>
> <resultMap id="personMap" class="com.pfizer.geca.batchProcess.Person">
> <result property="firstName" column="PER_FIRST_NAME"/>
> <result property="dept.name" column="DEPT_NAME"/>
> </resultMap>
>
> <select id="getPersonByDept1" resultMap="personMap">
> SELECT
> PER_FIRST_NAME,
> DEPT_NAME
> FROM PERSON, DEPT
> WHERE DEPT.DEPT_NO = PERSON.DEPT_NO
> AND DEPT.DEPT_NO=#value#
> </select>
>
> It throws me this error,
>
> Caused by: com.ibatis.common.exception.NestedRuntimeException:  
> Error configuring Result. Could not set ResultClass. Cause:  
> java.lang.ClassNotFoundException: com.comp.app.batchProcess.Person
> Caused by: java.lang.ClassNotFoundException:  
> com.comp.app.batchProcess.Person
> at com.ibatis.common.xml.NodeletParser.parse(NodeletParser.java:53)
> at com.ibatis.sqlmap.engine.builder.xml.SqlMapParser.parse 
> (SqlMapParser.java:45)
> at com.ibatis.sqlmap.engine.builder.xml.SqlMapConfigParser 
> $11.process(SqlMapConfigParser.java:347)
> at com.ibatis.common.xml.NodeletParser.processNodelet 
> (NodeletParser.java:112)
> ... 8 more
> Caused by: com.ibatis.common.exception.NestedRuntimeException:  
> Error parsing XPath '/sqlMap/resultMap'.  
> Cause:com.ibatis.common.exception.NestedRuntimeException: Error  
> configuring Result. Could not set ResultClass. Cause:  
> java.lang.ClassNotFoundException: com.comp.app.batchProcess.Person
> Caused by: java.lang.ClassNotFoundException:  
> com.comp.app.batchProcess.Person
> Caused by: com.ibatis.common.exception.NestedRuntimeException:  
> Error configuring Result. Could not set ResultClass. Cause:  
> java.lang.ClassNotFoundException: com.comp.app.batchProcess.Person
>
> Could you please let me know what should be done
>
> Thanks
>
> Zarar Siddiqi <zarar.siddiqi@utoronto.ca> wrote:
> Consider using composition:
>
> public class Person {
>     private Dept dept;
>     ...
> }
>
> Then you can use a resultMap and assign values to bean properties  
> by doing:
>
> <result property="dept.name" column="PER_DEPT_NAME"/>
>
> So you'll have:
>
> <select id="getPerson" resultMap="personMap">
>     ....
> </select>
>
> <resultMap id="personMap" class="com.comp.app.batchProcess.Person">
>     <result property="dept.name" column="PER_DEPT_NAME"/>
>     ......
> </resultMap>
>
> Zarar
>
> ----- Original Message -----
> From: radha rukmani
> To: user-java@ibatis.apache.org
> Sent: Wednesday, January 04, 2006 5:44 PM
> Subject: sql joins in ibatis
>
> Hi
> I am new to iBATIS. I was able to run the person example in the  
> ibatis website.
> For one table, the example says,
> <select id="getPerson" resultClass="com.comp.app.batchProcess.Person">
>           SELECT
>                PER_ID as id,
>                PER_FIRST_NAME as firstName,
>                PER_LAST_NAME as lastName,
>                PER_BIRTH_DATE as birthDate,
>                PER_WEIGHT_KG as weightInKilograms,
>                PER_HEIGHT_M as heightInMeters
>           FROM PERSON
>           WHERE PER_ID=#value#
>      </select>
> but if i want details from two tables, say person and dept table. I  
> have two bean classes person.java and dept.java
> and if i want to select like,
> select per_id as id, per_first_name as firstname, dept_name as  
> deptname from person,dept where dept_no = 2
> now  resultClass="com.comp.app.batchProcess.Person" and   
> "com.comp.app.batchProcess.Dept"
> how to get around this. Any help is greatly appreciated.
> Thanks
>
> Yahoo! DSL Something to write home about. Just $16.99/mo. or less
>
>
> Yahoo! Photos
> Ring in the New Year with Photo Calendars. Add photos, events,  
> holidays, whatever.


Mime
View raw message