ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Petr V." <greatman...@yahoo.com>
Subject Composite 1-1 Relationship
Date Tue, 20 Jan 2009 20:07:53 GMT
This is a very basic problem, and I have tried many combination but it is not working at all.

I have two table , let assume, there is 1-1 relationship for simplification of problem at
hand

Teacher(id, name) 
Student(id,name,teacher_id)

The two beans are 

public class Teacher {
    private Integer id;
    private String name;   
    private Integer student_Id;        
    ......
}

public class Student {
    private Integer id;
    private String name;  
    private Integer teacher_id;    
   ......
}

SQL config MAp is 

<resultMap id="TeacherResultMap" class="Teacher">
    <result property="id" column="id"/>
    <result property="name" column="name"/>
    <result property="student_id" column="id" select="findStudentByTeacherId"/>
</resultMap>


<select id="findStudentByTeacherId" resultClass="int">
    select id  from Student where id = #value#
</select>


<select id="findTeacherById" resultMap="TeacherResultMap">
    select id , name from Teacher where id = #value#
</select>

My Test code calls 

queryForObject("findTeacherById", id); 

But I get the following exception

Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in maps/JOB_SqlMap.xml.  
--- The error occurred while applying a result map.  
--- Check the JOB.TeacherResultMap.  
--- Check the result mapping for the 'student_id' property.  
--- Cause: java.lang.NullPointerException
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
    at org.springframework.orm.ibatis.SqlMapClientTemplate$1.doInSqlMapClient(SqlMapClientTemplate.java:273)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:209)
    ... 27 more
Caused by: java.lang.NullPointerException
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.endTransaction(SqlMapExecutorDelegate.java:734)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.endTransaction(SqlMapSessionImpl.java:176)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.endTransaction(SqlMapClientImpl.java:153)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.autoEndTransaction(SqlMapExecutorDelegate.java:835)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:525)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
    at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:75)
    at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.loadResult(ResultLoader.java:57)
    at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getNestedSelectMappingValue(ResultMap.java:510)
    at com.ibatis.sqlmap.engine.mapping.result.ResultMap.getResults(ResultMap.java:341)
    at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:384)
    at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleMultipleResults(SqlExecutor.java:300)
    at com.ibatis.sqlmap.engine.execution.SqlExecutor.executeQuery(SqlExecutor.java:189)
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.sqlExecuteQuery(MappedStatement.java:221)
    at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:189)
    ... 33 more






      
Mime
View raw message