ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petr V." <greatman...@yahoo.com>
Subject Re: Composite 1-1 Relationship
Date Wed, 21 Jan 2009 00:48:10 GMT
Thanks Larry for helping me out. What a miserable mistake at my end :-( Just started iBatis
and had no idea that xml configuration could be changed from dot net to java.

Any how, here is a working example for archives so if some one new search then he could find
a working example.

<resultMap id="TeacherResultMap" class="Teacher" groupBy="id" >
    <result property="id" />
    <result property="name" />    
    <result property="sid" resultMap="NAMESPACE.StudentResultMap"/>
</resultMap>

<resultMap id="StudentResultMap" class="Student" >
  <result property="id" column="stu_id"/>
  <result property="name" column="stu_Name"/>
  <result property="tid" column="stu_tid"/>
</resultMap>


<select id="findTeacher"  parameterClass="int" resultMap="TeacherResultMap">
    select t.id  , t.name , s.id as stu_id, s.name as stu_Name , s.tid as stu_tid from
Teacher t left join student s on t.id = s.tid where t.id = #value#
</select>

public class Student {
    private Integer id;
    private String  name;  
    private Integer tid;
    
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getTid() {
        return tid;
    }
    public void setTid(Integer tid) {
        this.tid = tid;
    }
}


public class Teacher {

    private Integer id;
    private String name;  
    private List<Student> sid;   
    
    public Integer getId() {
        return id;
    }
    public List<Student> getSid() {
        return sid;
    }
    public void setSid(List<Student> sid) {
        this.sid = sid;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }    
}

Call to iBatis via Spring

return (Teacher) getSqlMapClientTemplate().queryForObject("findTeacher", id);  

Thanks,

Petr
--- On Wed, 1/21/09, Larry Meadors <larry.meadors@gmail.com> wrote:
From: Larry Meadors <larry.meadors@gmail.com>
Subject: Re: Composite 1-1 Relationship
To: user-java@ibatis.apache.org, greatman787@yahoo.com
Date: Wednesday, January 21, 2009, 3:46 AM

That's for the .net version.

On Tue, Jan 20, 2009 at 3:42 PM, Petr V. <greatman787@yahoo.com> wrote:
> I strictly followed the steps at
> http://ibatisnet.sourceforge.net/DevGuide/ar01s03.html#d0e1036 but no
luck.
>



      
Mime
View raw message