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 Tue, 20 Jan 2009 22:42:04 GMT
Can any body please help me, I am now getting very frustrated. Whole day consumed and no progress
to show :-(

I strictly followed the steps at http://ibatisnet.sourceforge.net/DevGuide/ar01s03.html#d0e1036
but no luck.

I converted my code to 1-M

public class Teacher {
    private Integer id;
    private String name;  
    private List<Student> sid;
   
    public List<Student> getSid() {
        return sid;
    }
    public void setSid(List<Student> sid) {
        this.sid = sid;
    }
    .........
}

public class Student {

    private Integer id;
    private String name;  
    private Integer teacher_id;
    ......
}

MY SQL Map

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

<resultMap id="StudentResultMap" class="Student">
  <result property="id" column="id"/>
  <result property="name" column="name"/>
  <result property="teacher_id" column="teacher_id"/>
</resultMap>

<select id="findStudentByTeacherId" resultMap="StudentResultMap">
    select * from Student where id = #value#
</select>

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

The exception log is 

org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation; uncategorized
SQLException for SQL []; SQL state [null]; error code [0];   
--- 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 'sid' property.  
--- Cause: java.lang.NullPointerException; nested exception is 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 'sid' property.  
--- Cause: java.lang.NullPointerException
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.execute(SqlMapClientTemplate.java:212)
    at org.springframework.orm.ibatis.SqlMapClientTemplate.queryForObject(SqlMapClientTemplate.java:271)
    at com.vmware.jcollector.scheduler.daoimpl.TeacherDAOImpl.getTeacher(TeacherDAOImpl.java:21)
    at com.vmware.jcollector.AppTest.testJobDao(AppTest.java:133)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:168)
    at junit.framework.TestCase.runBare(TestCase.java:134)
    at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:76)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:338)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:997)
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 'sid' 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.queryForList(SqlMapExecutorDelegate.java:574)
    at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:541)
    at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForList(SqlMapSessionImpl.java:118)
    at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForList(SqlMapClientImpl.java:94)
    at com.ibatis.sqlmap.engine.mapping.result.loader.ResultLoader.getResult(ResultLoader.java:70)
    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

Debug Log is 

2009-01-20 14:34:39,254 [main] DEBUG java.sql.Connection  - {conn-100000} Connection
2009-01-20 14:34:39,254 [main] DEBUG java.sql.Connection  - {conn-100000} Preparing Statement:  
select id , name from Teacher where id = ? 
2009-01-20 14:34:39,457 [main] DEBUG java.sql.PreparedStatement  - {pstm-100001} Executing
Statement:   select id , name from Teacher where id = ? 
2009-01-20 14:34:39,457 [main] DEBUG java.sql.PreparedStatement  - {pstm-100001} Parameters:
[1]
2009-01-20 14:34:39,457 [main] DEBUG java.sql.PreparedStatement  - {pstm-100001} Types: [java.lang.Integer]
2009-01-20 14:34:39,473 [main] DEBUG java.sql.ResultSet  - {rset-100002} ResultSet

Thanks,

Petr

--- On Wed, 1/21/09, Petr V. <greatman787@yahoo.com> wrote:
From: Petr V. <greatman787@yahoo.com>
Subject: Composite 1-1 Relationship
To: user-java@ibatis.apache.org
Date: Wednesday, January 21, 2009, 1:07 AM

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