Skip to content
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

BeanPropertyRowMapper should be able to convert SQL timestamp to java.time.LocalDate/LocalTime [SPR-14898] #19464

Closed
spring-projects-issues opened this issue Nov 11, 2016 · 5 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 11, 2016

gopalarao opened SPR-14898 and commented

Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.sql.Timestamp] to required type [java.time.LocalDate] for property 'effectiveFromDate': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306)


Affects: 4.3.2

Issue Links:

  • #18461 BeanPropertyRowMapper should use ConversionService for date-time support
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 11, 2016

gopalarao commented

I am using spring jdbc template +java8+ oracle ojdbc6

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 11, 2016

Juergen Hoeller commented

Could you post the full stacktrace please, as well as the database result field type? I assume you're using BeanPropertyRowMapper there?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 11, 2016

gopalarao commented

That;s correct. I am using BeanPropertyRowMapper.

stacktrace:
org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type [java.sql.Timestamp] to required type [java.time.LocalDate] for property 'effectiveFromDate'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.sql.Timestamp] to required type [java.time.LocalDate] for property 'effectiveFromDate': no matching editors or conversion strategy found
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:591)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:449)
at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:260)
at org.springframework.jdbc.core.BeanPropertyRowMapper.mapRow(BeanPropertyRowMapper.java:297)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:697)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:726)
at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:794)
.
.
.
.
..
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.sql.Timestamp] to required type [java.time.LocalDate] for property 'effectiveFromDate': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:306)
at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
... 44 more

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 22, 2016

Juergen Hoeller commented

Note that the correct representation of a java.sql.Timestamp is actually java.time.LocalDateTime, which we automatically convert since #18461 already. java.time.LocalDate corresponds to java.sql.Date instead, which we auto-convert as a pair as well, just like java.time.LocalTime and java.sql.Time... all based on the toLocalXXX conversion methods on the java.sql data types themselves.

However, I suppose your JDBC driver returns a java.sql.Timestamp here, probably from a generic ResultSet.getObject call that BeanPropertyRowMapper falls back to, and you're trying to map it to a java.time.LocalDate nevertheless... We can leniently accept this but unfortunately it requires special support in JdbcUtils.getResultSetValue since it doesn't follow from the JDK's standard conversion rules.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 22, 2016

Juergen Hoeller commented

I've added extra checks to JdbcUtils.getResultSetValue, extracting a java.sql.Date / java.sql.Time value from the result set for a required type of java.time.LocalDate / java.time.LocalTime, respectively. This will then be further converted by BeanPropertyRowMapper's ConversionService through the regular toLocalDate / toLocalTime methods on java.sql.Date / java.sql.Time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.