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

No converter found capable of converting from type [java.time.LocalDateTime] to type [java.util.Date] #1386

Closed
funky-eyes opened this issue Nov 17, 2022 · 6 comments
Labels
status: invalid An issue that we don't feel is valid

Comments

@funky-eyes
Copy link

Caused by: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.LocalDateTime] to type [java.util.Date]
        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.r2dbc.convert.MappingR2dbcConverter.getPotentiallyConvertedSimpleRead(MappingR2dbcConverter.java:277)
        at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readValue(MappingR2dbcConverter.java:201)
        at org.springframework.data.r2dbc.convert.MappingR2dbcConverter.readFrom(MappingR2dbcConverter.java:182)
        ... 70 common frames omitted

Is there any way I can convert it correctly please?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 17, 2022
@funky-eyes
Copy link
Author

I add data using the jdbc method and then read it using spring-data-r2dbc and get the error as above, if I always use spring-data-r2dbc I don't have this problem, when I mix the two, r2dbc doesn't convert the properties correctly

@mp911de
Copy link
Member

mp911de commented Nov 18, 2022

You can register a custom converter to convert JSR-310 temporal types to the old java.util.Date applying your timezone mapping rules.

@funky-eyes
Copy link
Author

You can register a custom converter to convert JSR-310 temporal types to the old java.util.Date applying your timezone mapping rules.

What I don't understand is why data inserted via r2dbc can be read normally under the same table, and data inserted via jdbc has a conversion failure when read by r2dbc?

@mp911de
Copy link
Member

mp911de commented Nov 18, 2022

Your database table isn't differentiating between JSR-310 and java.util.Date types, but your domain model does.

JDBC supports the old temporal types while R2DBC doesn't support java.util.Date in favor of more precise temporal types to reflect what's actually stored within the database. java.util.Date is broken in the sense as it always requires additional context (such as Calendar or TimeZone) and configuration to work correctly.

@funky-eyes
Copy link
Author

@mp911de Please follow this issue spring-projects/spring-data-examples#652

And my domain model has been using the Date, and then not with the use of jdbc applications to operate the same table of data is working properly, once working with jdbc applications, jdbc applications to write the data read will fail, while the use of r2dbc applications to write their own data can be read normally

@Table("global_table")
public class GlobalTransaction {

    @Id
    private String xid;

    private Long transactionId;

    private Integer status;

    private String applicationId;

    private String transactionServiceGroup;

    private String transactionName;

    private Integer timeout;

    private Long beginTime;

    private String applicationData;

    private Date gmtCreate;

    private Date gmtModified;

    /**
     * Gets xid.
     *
     * @return the xid
     */
    public String getXid() {
        return xid;
    }

    /**
     * Sets xid.
     *
     * @param xid the xid
     */
    public void setXid(String xid) {
        this.xid = xid;
    }

    /**
     * Gets status.
     *
     * @return the status
     */
    public int getStatus() {
        return status;
    }

    /**
     * Sets status.
     *
     * @param status the status
     */
    public void setStatus(int status) {
        this.status = status;
    }

    /**
     * Gets application id.
     *
     * @return the application id
     */
    public String getApplicationId() {
        return applicationId;
    }

    /**
     * Sets application id.
     *
     * @param applicationId the application id
     */
    public void setApplicationId(String applicationId) {
        this.applicationId = applicationId;
    }

    /**
     * Gets transaction service group.
     *
     * @return the transaction service group
     */
    public String getTransactionServiceGroup() {
        return transactionServiceGroup;
    }

    /**
     * Sets transaction service group.
     *
     * @param transactionServiceGroup the transaction service group
     */
    public void setTransactionServiceGroup(String transactionServiceGroup) {
        this.transactionServiceGroup = transactionServiceGroup;
    }

    /**
     * Gets transaction name.
     *
     * @return the transaction name
     */
    public String getTransactionName() {
        return transactionName;
    }

    /**
     * Sets transaction name.
     *
     * @param transactionName the transaction name
     */
    public void setTransactionName(String transactionName) {
        this.transactionName = transactionName;
    }

    /**
     * Gets timeout.
     *
     * @return the timeout
     */
    public int getTimeout() {
        return timeout;
    }

    /**
     * Sets timeout.
     *
     * @param timeout the timeout
     */
    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    /**
     * Gets begin time.
     *
     * @return the begin time
     */
    public long getBeginTime() {
        return beginTime;
    }

    /**
     * Sets begin time.
     *
     * @param beginTime the begin time
     */
    public void setBeginTime(long beginTime) {
        this.beginTime = beginTime;
    }

    /**
     * Gets transaction id.
     *
     * @return the transaction id
     */
    public long getTransactionId() {
        return transactionId;
    }

    /**
     * Sets transaction id.
     *
     * @param transactionId the transaction id
     */
    public void setTransactionId(long transactionId) {
        this.transactionId = transactionId;
    }

    /**
     * Gets application data.
     *
     * @return the application data
     */
    public String getApplicationData() {
        return applicationData;
    }

    /**
     * Sets application data.
     *
     * @param applicationData the application data
     */
    public void setApplicationData(String applicationData) {
        this.applicationData = applicationData;
    }

    /**
     * Gets gmt create.
     *
     * @return the gmt create
     */
    public Date getGmtCreate() {
        return gmtCreate;
    }

    /**
     * Sets gmt create.
     *
     * @param gmtCreate the gmt create
     */
    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    /**
     * Gets gmt modified.
     *
     * @return the gmt modified
     */
    public Date getGmtModified() {
        return gmtModified;
    }

    /**
     * Sets gmt modified.
     *
     * @param gmtModified the gmt modified
     */
    public void setGmtModified(Date gmtModified) {
        this.gmtModified = gmtModified;
    }

    /**
     * Sets transactionId
     * @param transactionId the transactionId
     */
    public void setTransactionId(Long transactionId) {
        this.transactionId = transactionId;
    }

    /**
     * Sets status
     * @param status the status
     */
    public void setStatus(Integer status) {
        this.status = status;
    }

    /**
     * Sets timeout
     * @param timeout the timeout
     */
    public void setTimeout(Integer timeout) {
        this.timeout = timeout;
    }

    /**
     * Sets begin time
     * @param beginTime the begin time
     */
    public void setBeginTime(Long beginTime) {
        this.beginTime = beginTime;
    }

    @Override
    public String toString() {
        return StringUtils.toString(this);
    }

}

@mp911de
Copy link
Member

mp911de commented Nov 22, 2022

What I don't understand is why data inserted via r2dbc can be read normally under the same table, and data inserted via jdbc has a conversion failure when read by r2dbc?

R2DBC doesn't support java.util.Date in the specification, therefore you need to provide a converter if you wish to use Date in your domain model.

Closing this one as there's nothing we can do from our side.

@mp911de mp911de closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2022
@mp911de mp911de added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants