浏览 3636 次
锁定老帖子 主题:dao类
精华帖 (0) :: 良好帖 (0) :: 新手帖 (3) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-08-17   最后修改:2012-08-18
yangbingy000 写道

//dao类
public interface EmpDao {
public List<Emp> findEmpByEname(String ename);
           public List<Emp> findEmps(Date beginDate,Date endDate,Float hisal,Float locsal);

}

//实现类
public class EmpDaoImpl implements EmpDao {
private EmpDaoImpl(){}
private static EmpDaoImpl daoImpl=new EmpDaoImpl();
public static EmpDaoImpl getInstance(){
return daoImpl;
}

private static SqlMapClient sqlMapClient=IbatisUtil.getSqlMapClient();

@Override
public List<Emp> findEmpByEname(String ename) {
try {
return sqlMapClient.queryForList("findEmpByname",ename);
} catch (SQLException e) {
throw new DaoException(e);
}
}
//emp.xml的配置
<select id="findEmps" parameterClass="java.util.Map" resultClass="com.pk.po.Emp">
<![CDATA[select * from emp where hiredate between #beginDate# and #endDate# and sal < #hisal# and sal > #locsal#]]></select>

//测试类
public void testEmps() throws Exception {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date beginDate=sdf.parse("1981-01-01");
Date endDate=sdf.parse("1982-12-12");
float hisal=5000;
float locsal=2000;

List<Emp> list=empDao.findEmps(beginDate, endDate, hisal, locsal);
for (Emp emp : list) {
System.out.println(emp);
}

}

//异常

com.pk.exectpion.DaoException: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/pk/po/Emp.xml. 
--- The error occurred while applying a result map. 
--- Check the findEmps-AutoResultMap. 
--- The error happened while setting a property on the result object. 
--- Cause: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.pk.dao.impl.EmpDaoImpl.findEmps(EmpDaoImpl.java:51)
at com.pk.test.TestIbatis.testEmps(TestIbatis.java:92)
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:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/pk/po/Emp.xml. 
--- The error occurred while applying a result map. 
--- Check the findEmps-AutoResultMap. 
--- The error happened while setting a property on the result object. 
--- Cause: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
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.pk.dao.impl.EmpDaoImpl.findEmps(EmpDaoImpl.java:49)
... 17 more
Caused by: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:52)
at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.setResultObjectValues(ResultMap.java:371)
at com.ibatis.sqlmap.engine.mapping.result.AutoResultMap.setResultObjectValues(AutoResultMap.java:57)
at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:385)
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)
... 23 more
Caused by: java.lang.IllegalArgumentException
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 com.ibatis.common.beans.MethodInvoker.invoke(MethodInvoker.java:17)
at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:46)
... 32 more

   发表时间:2012-08-18  
yangbingy000 写道

//dao类
public interface EmpDao {
public List<Emp> findEmpByEname(String ename);
           public List<Emp> findEmps(Date beginDate,Date endDate,Float hisal,Float locsal);

}

//实现类
public class EmpDaoImpl implements EmpDao {
private EmpDaoImpl(){}
private static EmpDaoImpl daoImpl=new EmpDaoImpl();
public static EmpDaoImpl getInstance(){
return daoImpl;
}

private static SqlMapClient sqlMapClient=IbatisUtil.getSqlMapClient();

@Override
public List<Emp> findEmpByEname(String ename) {
try {
return sqlMapClient.queryForList("findEmpByname",ename);
} catch (SQLException e) {
throw new DaoException(e);
}
}
//emp.xml的配置
<select id="findEmps" parameterClass="java.util.Map" resultClass="com.pk.po.Emp">
<![CDATA[select * from emp where hiredate between #beginDate# and #endDate# and sal < #hisal# and sal > #locsal#]]></select>

//测试类
public void testEmps() throws Exception {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date beginDate=sdf.parse("1981-01-01");
Date endDate=sdf.parse("1982-12-12");
float hisal=5000;
float locsal=2000;

List<Emp> list=empDao.findEmps(beginDate, endDate, hisal, locsal);
for (Emp emp : list) {
System.out.println(emp);
}

}

//异常

com.pk.exectpion.DaoException: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/pk/po/Emp.xml. 
--- The error occurred while applying a result map. 
--- Check the findEmps-AutoResultMap. 
--- The error happened while setting a property on the result object. 
--- Cause: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.pk.dao.impl.EmpDaoImpl.findEmps(EmpDaoImpl.java:51)
at com.pk.test.TestIbatis.testEmps(TestIbatis.java:92)
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:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: com.ibatis.common.jdbc.exception.NestedSQLException:  
--- The error occurred in com/pk/po/Emp.xml. 
--- The error occurred while applying a result map. 
--- Check the findEmps-AutoResultMap. 
--- The error happened while setting a property on the result object. 
--- Cause: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryWithCallback(MappedStatement.java:204)
at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForList(MappedStatement.java:139)
at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForList(SqlMapExecutorDelegate.java:567)
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.pk.dao.impl.EmpDaoImpl.findEmps(EmpDaoImpl.java:49)
... 17 more
Caused by: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException
at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:52)
at com.ibatis.sqlmap.engine.exchange.JavaBeanDataExchange.setData(JavaBeanDataExchange.java:112)
at com.ibatis.sqlmap.engine.mapping.result.ResultMap.setResultObjectValues(ResultMap.java:371)
at com.ibatis.sqlmap.engine.mapping.result.AutoResultMap.setResultObjectValues(AutoResultMap.java:57)
at com.ibatis.sqlmap.engine.mapping.statement.RowHandlerCallback.handleResultObject(RowHandlerCallback.java:64)
at com.ibatis.sqlmap.engine.execution.SqlExecutor.handleResults(SqlExecutor.java:385)
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)
... 23 more
Caused by: java.lang.IllegalArgumentException
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 com.ibatis.common.beans.MethodInvoker.invoke(MethodInvoker.java:17)
at com.ibatis.sqlmap.engine.accessplan.PropertyAccessPlan.setProperties(PropertyAccessPlan.java:46)
... 32 more

0 请登录后投票
   发表时间:2012-08-22  
Cause: java.lang.RuntimeException: Error setting property 'setComm' of 'comm=0, deptno=0, empno=7566, ename=JONES, hiredate=Thu Apr 02 00:00:00 CST 1981, job=MANAGER, mgr=7839, sal=2975'.  Cause: java.lang.IllegalArgumentException

仔细阅读这句话 就知道什么原因了
0 请登录后投票
   发表时间:2012-08-24  
很明显是属性参数绑定的时候参数不合规。
0 请登录后投票
   发表时间:2012-10-15  
编码问题。
return sqlMapClient.queryForList("findEmpByname",ename);   --findEmpByname


<select id="findEmps" parameterClass="java.util.Map" resultClass="com.pk.po.Emp"> --findEmps

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics