Skip to content

BeanPropertyRowMapper should use ConversionService for date-time support [SPR-13888] #18461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Jan 25, 2016 · 1 comment
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 25, 2016

Radmila opened SPR-13888 and commented

Program is using org.springframework.jdbc.core.BeanPropertyRowMapper to map result set to the bean.
When mapping timestamp resultset column to the bean's java.time.LocalDateTime field, process fails with
org.springframework.jdbc.support.JdbcUtils getResultSetValue with error
IllegalStateException: Cannot convert value of type [java.sql.Timestamp] to required type [java.time.LocalDateTime] for property 'nameproperty': no matching editors or conversion strategy found.

Problem with spring 4.1.6.RELEASE. and JDK 1.8


Issue Links:

Referenced from: commits 7c96059

1 votes, 3 watchers

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The problem is not so much in JdbcUtils which simply returns what the JDBC driver gives us. We're trying JDBC 4.1's getObject(int, Class) with a java.time.LocalDateTime argument in this case, but if that call happens to fail against your JDBC driver, we'll just plain getObject(int) which usually returns a java.sql.Timestamp in such a case. I suppose that's your scenario.

However, arguably, BeanPropertyRowMapper should use its BeanWrapper preconfigured with a DefaultConversionService: Our date-time conversion capabilities are built-in there, so even if a java.sql.Timestamp comes along, we can convert it to a java.time.LocalDateTime bean property on our own. I'm looking at this as a default for Spring Framework 4.3.

For the time being, you could override the BeanPropertyRowMapper.initBeanWrapper method and call bw.setConversionService(new DefaultConversionService()); yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants