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

Upgrading to Spring Data JDBC 2.1.3 results in ConverterNotFoundException for String to Duration #959

Closed
dmkeen opened this issue Apr 11, 2021 · 5 comments
Assignees
Labels
status: duplicate A duplicate of another issue type: regression A regression from a previous release

Comments

@dmkeen
Copy link

dmkeen commented Apr 11, 2021

I have a Spring Data repository that returns an object with a Duration field which is stored in the database as a String. In Spring Data JDBC 2.1.2 the object is created and returned successfully. After upgrading to Spring Data JDBC 2.1.3, the following exception is thrown:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.time.Duration]

I've created a project that demonstrates the issue here: https://github.com/dmkeen/spring-boot-2.4.2-issue

Because the issue presented itself when upgrading Spring Boot, I filed an issue there first. Scott Frederick helped narrow down the problem - please see his analysis here: spring-projects/spring-boot#25878.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 11, 2021
@schauder
Copy link
Contributor

I strongly suspect this is a duplicate of spring-projects/spring-data-commons#2223

You should be able to fix this by registering some custom conversion for the conversion from String to Duration and back.

@schauder schauder added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 12, 2021
@mp911de
Copy link
Member

mp911de commented Apr 12, 2021

Attaching stack trace:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.time.Duration]

	at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:322)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:195)
	at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:175)
	at org.springframework.data.relational.core.conversion.BasicRelationalConverter.getPotentiallyConvertedSimpleRead(BasicRelationalConverter.java:241)
	at org.springframework.data.relational.core.conversion.BasicRelationalConverter.readValue(BasicRelationalConverter.java:164)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter.readValue(BasicJdbcConverter.java:244)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.readFrom(BasicJdbcConverter.java:488)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.readOrLoadProperty(BasicJdbcConverter.java:457)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.populateProperties(BasicJdbcConverter.java:436)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.createInstanceInternal(BasicJdbcConverter.java:568)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter$ReadingContext.mapRow(BasicJdbcConverter.java:414)
	at org.springframework.data.jdbc.core.convert.BasicJdbcConverter.mapRow(BasicJdbcConverter.java:348)
	at org.springframework.data.jdbc.core.convert.EntityRowMapper.mapRow(EntityRowMapper.java:67)

@schauder schauder self-assigned this Apr 12, 2021
@schauder
Copy link
Contributor

schauder commented Apr 12, 2021

We should properly support the JSR310 converters in Spring Data JDBC.

This is probably already fixed by #937 for the current master

@dmkeen
Copy link
Author

dmkeen commented Apr 18, 2021

Thanks for looking into this!

You should be able to fix this by registering some custom conversion for the conversion from String to Duration and back

I was hoping I wouldn't have to! :)

This is probably already fixed by #937 for the current master

I see that this PR is included in Spring Data 2021.0.0, so I've tested with Spring Boot 2.5.0-RC1 (which includes 2012.0.0) and the issue is resolved. Thanks!

@schauder schauder added the status: duplicate A duplicate of another issue label May 28, 2021
@schauder
Copy link
Contributor

Closing this as a duplicate of #937

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

4 participants