类'Employee'中没有名为'first_name'的READABLE属性

时间:2013-11-29 11:39:22

标签: java ibatis

我是ibatis的新手,

我在ibatis写了一个小程序。

但是我得到了以下错误。我试过各种各样的方式。我不知道如何解决。

有谁可以告诉我为什么会发生这种情况,以及如何避免这种错误?

Exception in thread "main" com.ibatis.common.exception.NestedRuntimeException: Error occurred.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMapConfig/sqlMap'.  Cause: com.ibatis.common.xml.NodeletException: Error parsing XML.  Cause: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMap/update'.  Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.exception.NestedRuntimeException: Error parsing XPath '/sqlMap/update'.  Cause: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'
Caused by: 
com.ibatis.common.beans.ProbeException: There is no READABLE property named 'first_name' in class 'Employee'

代码: Employee.java它包含first_name,last_name,id,salary

的getter和setter方法

employeedao.java

public static void main()
{
Reader rd=Resources.getResourceAsReader("sql-maps-config.xml");
SqlMapClient smc = SqlMapClientBuilder.buildSqlMapClient(rd);
System.out.println("Going to read records.....");
 rec.setId(1);
           rec.setFirstName("Roma");
           smc.update("UserTEO.update", rec );
           System.out.println("Record updated Successfully ");

           System.out.println("Going to read records.....");
 List <employeedao> ems = (List<employeedao>)
           smc.queryForList("UserTEO.getAll", null);
           employeedao em = null;
           for (employedao e : ems) {
              System.out.print("  " + e.getId());
             // System.out.print("  " + e.getFirstName());
           //   System.out.print("  " + e.getLastName());
              System.out.print("  " + e.getSalary());
              em = e; 
              System.out.println("");
           }    

       System.out.println("Records Read Successfully ");
}

employee.xml      

 <select id="getAll" resultClass="Employee">
   SELECT * FROM EMPLOYEE
</select>

<update id="update" parameterClass="Employee">
   UPDATE EMPLOYEE
   SET    first_name = #first_name#
   WHERE  id = #id#
</update>

</sqlMap>

1 个答案:

答案 0 :(得分:1)

getter是

public String getFirstName()

因此,该属性为firstName,而非first_name

请参阅http://docs.oracle.com/javase/tutorial/javabeans/writing/properties.html