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

LocalDate, LocalDateTime are not DATE, not TIMESTAMP #1867

Closed
KirillKurdyukov opened this issue Aug 27, 2024 · 6 comments
Closed

LocalDate, LocalDateTime are not DATE, not TIMESTAMP #1867

KirillKurdyukov opened this issue Aug 27, 2024 · 6 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply status: feedback-provided Feedback has been provided

Comments

@KirillKurdyukov
Copy link

KirillKurdyukov commented Aug 27, 2024

Based on the motives: spring-projects/spring-framework#28778

I conclude that LocalDate is a DATE sqlCode and LocalDateTime is a TIMESTAMP.
but in JdbcUtil:
https://github.com/spring-projects/spring-data-relational/blob/main/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/support/JdbcUtil.java

I didn't quite understand what happened to these types?
I using 3.3.3 version, and have UNKNOWN type for LocalDateTime, Timestamp for LocalDate

PROPERTY TYPE: class java.time.LocalDate -> class java.sql.Timestamp -> TIMESTAMP
PROPERTY TYPE: class java.time.LocalDateTime -> class java.time.LocalDateTime -> UNKNOWN

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 27, 2024
@KirillKurdyukov KirillKurdyukov changed the title LocalDate, LocalDateTime are not DATE, TIMESTAMP. Custom sqlCode LocalDate, LocalDateTime are not DATE, not TIMESTAMP. Custom sqlCode Aug 27, 2024
@schauder
Copy link
Contributor

Sorry, I have a hard time understanding what your question is.

This part:

And how to pass custom SQL code? Example Json
import java.sql.SQLType; - custom implementation type

doesn't seem to be related to the rest of the question at all, correct?
Please limit yourself to a single question per posting. Feel free to create multiple issues if there are problems.

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 29, 2024
@KirillKurdyukov KirillKurdyukov changed the title LocalDate, LocalDateTime are not DATE, not TIMESTAMP. Custom sqlCode LocalDate, LocalDateTime are not DATE, not TIMESTAMP Aug 29, 2024
@KirillKurdyukov
Copy link
Author

KirillKurdyukov commented Aug 30, 2024

Spring Data JDBC for LocalDate, LocalDateTime data types used SqlType TIMESTAMP и UNKNOW, I expect DATE and TIMESTAMP

JdbcUtil.java convertation:
PROPERTY TYPE: class java.time.LocalDate -> class java.sql.Timestamp -> TIMESTAMP
PROPERTY TYPE: class java.time.LocalDateTime -> class java.time.LocalDateTime -> UNKNOWN

https://github.com/spring-projects/spring-data-relational/blob/main/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/support/JdbcUtil.java

Based on the motives: spring-projects/spring-framework#28778

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Aug 30, 2024
@schauder
Copy link
Contributor

Still, what is the actual problem? Does data get stored wrongly? Please provide a sample.

@schauder schauder added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Aug 30, 2024
@spring-projects-issues
Copy link

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Sep 6, 2024
@KirillKurdyukov
Copy link
Author

Hello!
I think this for classic set of databases, there is no problem. LocalDate or LocalDateTime was prepared JDBC drivers of vendors. I implemented org.springframework.data.relational.core.dialect.AbstractDialect for YDB.
I found that since java.time.LocalDate with JDBCType.TIMESTAMP in JDBC PreparedStatement.
The client expected a Date type in the table for LocalDate.
it's not critical, I've implemented

public record YQLType(PrimitiveType type) implements SQLType 

public @interface YdbType {
    String value();
}

public class YdbMappingJdbcConverter extends MappingJdbcConverter {
    public YdbMappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
                                   CustomConversions conversions, JdbcTypeFactory typeFactory) {
        super(context, relationResolver, conversions, typeFactory);
    }

    @Override
    public SQLType getTargetSqlType(RelationalPersistentProperty property) {
        return property.isAnnotationPresent(YdbType.class) ?
                new YQLType(PrimitiveType.valueOf(property.getRequiredAnnotation(YdbType.class).value())) :
                super.getTargetSqlType(property);
    }
}

Problem is resolved

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Sep 12, 2024
@schauder
Copy link
Contributor

I don't think there is anything here to do for us.

@schauder schauder self-assigned this Sep 12, 2024
@schauder schauder added the status: declined A suggestion or change that we don't feel we should currently apply label Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply status: feedback-provided Feedback has been provided
Projects
None yet
Development

No branches or pull requests

3 participants