Original address:
http://blog.csdn.net/will_awoke/article/details/12617383
has been using ORM, today with JdbcTemplate again depressed once again.
First look at this method:
At first glance, I want to pass a generic T (the actual code execution, this T can be my custom bean), and then I can return a list<t>, that is, the collection of generics (pure ORM idea Ah!). But also dug a big pit ~)
Thus, the following code appears:
[Java]View Plaincopy
- list<student> list = jdbctemplate.queryforlist (sql, Student. Class);
One execution, found out the exception:
ERROR [Com.ruhuiyun.studentmanager.aop.LogAdvice]- Org.springframework.jdbc.IncorrectResultSetColumnCountException:Incorrect column count:expected 1, actual 8:incorre CT column count:expected 1, actual 8
The exception is very clear, need one, to the people eight, that is, they are not saved list. Very strange, after a search, found not so, and ran off ~
Originally this t, only supports integer.class string.class this kind of single data type, its own defined bean does not support. So I'm over the idea of this ORM.
Feelings if there is a need to encapsulate an object, you have to do it yourself.
This jdbctemplate is really unable to spit groove ~ as if back to the ancient times ~!
Update: wrote a wheel for Spring jdbctemplate query result set map reverse generation Java entity, http://blog.csdn.net/will_awoke/article/details/ 27683703, interested can look under.
Reference article:
http://forum.spring.io/forum/spring-projects/data/122343- Comparison-between-queryforlist-and-query-working-with-a-list-of-objects
Spring jdbctemplate queryforlist (String sql, class<t> ElementType) Easy to use-reproduced