-
Feb 9th, 2012, 04:59 PM
#1
Bean containing enum fails in SimpleJdbcTemplate.update but not with SimpleJDBCInsert
I have a Javabean which contains an enum. When I insert the object into my Oracle database everything works. The column for the enum is a varchar2, and the enum name is successfully stored. My code is:
SqlParameterSource parameters = new BeanPropertySqlParameterSource(bean);
Number newId = simpleJdbcInsert.executeAndReturnKey(parameters);
When I look at the log output, it appears that the SimpleJDBCInsert uses the table metadata to set the sql type (my enum is name JobStatus, and the name is PASSED):
Setting SQL statement parameter value: column index 8, parameter value [PASSED], value class com.tr.config.dashboard.job.JobStatus], SQL type 12
When I try to do an update using a SimpleJDBCTemplate on that row the update fails with "Invalid Column Type'.
The SimpleJDBCTemplate.update doesn't use the metadata to determine the column type, so I get an unknown column type. My code is:
simpleJdbcTemplate.update(updateSql, new BeanPropertySqlParameterSource(bean));
with the log output:
Setting SQL statement parameter value: column index 7, parameter value [PASSED], value class [com.tr.config.dashboard.job.JobStatus], SQL type unknown
Is there a way for me to configure a mapping so my enum always gets mapped to a varchar2? I want to avoid having to build the parameter map myself if possible as my project has an infrastructure in place to automatically inspect the beans and build the update sql. This works great as long as all of the fields map to known sql types.
Thanks for the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules