here is no getter for property named 'id' in 'class java.lang.Integer'

2,217 views
Skip to first unread message

wei pen

unread,
May 25, 2011, 5:10:07 AM5/25/11
to mybatis-user
Exception in thread "main"
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause:
org.apache.ibatis.reflection.ReflectionException: There is no getter
for property named 'id' in 'class java.lang.Integer'
### The error may exist in com/batis/po/MaperXml/company.xml
### The error may involve com.batis.mapper.CompanyMapper.getCompany
### The error occurred while executing a query
### Cause: org.apache.ibatis.reflection.ReflectionException: There is
no getter for property named 'id' in 'class java.lang.Integer'
at
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:
77)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:
69)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:
40)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:
70)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:38)
at $Proxy1.getCompany(Unknown Source)
at com.batis.test.Tester.main(Tester.java:32)
companyMapper.xml:
<mapper namespace="com.batis.mapper.CompanyMapper">

<!-- 获取全部数据字典类型 -->
<select id="getCompany" parameterType="int"
resultType="com.batis.po.Company">
select * from company where id = ${id};
</select>
</mapper>

Larry Meadors

unread,
May 25, 2011, 8:30:36 AM5/25/11
to mybati...@googlegroups.com
select * from company where id = ${value};

Guy Rouillier

unread,
Feb 20, 2013, 11:12:15 PM2/20/13
to mybati...@googlegroups.com
On 2/20/2013 4:45 PM, Jack Peterson wrote:
> select * from company where id = #{id}
> you can keep where it says id, thats the name of your column
> the $ is for properties, the # is for mybatis i believe to get the
> actual value of id

$ is for string substition, while # is for JDBC parameters. You can use
string substitution here, but there is no good reason to do so. While
sometimes string substitution is necessary (to make the table name
changeable at run-time, for instance), but it has risks of SQL
injection. So only use it when you have no viable alternatives.

--
Guy Rouillier
Reply all
Reply to author
Forward
0 new messages