-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
Spring JDBC does not recognize LocalDate and LocalDateTime in javaType to sqlType Mapping #28778
Comments
Good catch, those should have a standard SQL type mapping (even if this mapping mechanism is only really used in our
|
This commit adds mapping for two types from the `java.time` package, complementing the types that are already translatable to Sql types TIME, DATE and TIMESTAMP: - `OffsetTime` maps to a `TIME_WITH_TIMEZONE` - `OffsetDateTime` maps to a `TIMESTAMP_WITH_TIMEZONE` This is in accordance with the B.4 table provided in the JDBC 4.2 specification. When preparing statements, these `java.time` types use the `setObject` method. Tests covering the 5 `java.time` classes have also been added. See spring-projectsgh-28778 See spring-projectsgh-28527
This commit adds mapping for two types from the `java.time` package, complementing the types that are already translatable to Sql types TIME, DATE and TIMESTAMP: - `OffsetTime` maps to a `TIME_WITH_TIMEZONE` - `OffsetDateTime` maps to a `TIMESTAMP_WITH_TIMEZONE` This is in accordance with the B.4 table provided in the JDBC 4.2 specification. When preparing statements, these `java.time` types use the `setObject` method. Tests covering the 5 `java.time` classes have also been added. See gh-28778 See gh-28527 Closes gh-30123
First of all I would like to thank the spring framework team for doing there great work & making us available newer version and maintaining the older releases as well. I am not sure, whether I am posting my query on correct page or not, apology for this. Let's say, I have Date column in Oracle database table so the datatype is Date & that column has the index created. When ever we hit the database by passing the java.sql.Timestamp value in parameterized statement then that Date column is getting converted into Timestamp and which makes the indexes invalid for that Date column so this hits the performance issue. So as the workaround solution we have customized StatementCreatorUtils class & did the conversion from java.sql.Timestamp to oracle.sql.DATE if the DB type is oracle. So can anybody please reply on this whether this is the expected behavior or am I missing something here. Reply from the experts will really help me. I could see same topic had been discussed in past on stack overflow, adding the links here for reference. |
In the same StatementCreatorUtils class, there is a private static void setValue(PreparedStatement ps, int paramIndex, int sqlType, @nullable String typeName, @nullable Integer scale, Object inValue) method which performs for instance:
So if we pass a LocalDate inValue, we actually leave it up to the driver to manage it with the ps.setObject() call. Should we not have another check of the LocalDate type that converts it into a java.sl.Date and invokes ps.setDate() instead?
|
I didn't quite understand what happened to these types? PROPERTY TYPE: class java.time.LocalDate -> class java.sql.Timestamp -> TIMESTAMP |
Please note that this issue was closed 2 years ago. If you believe you have encountered a bug against a supported Spring Framework version, please create a new issue to discuss that and provide a minimal sample application that reproduces the issue. Thanks |
In class, StatementCreatorUtils, spring jdbc does not recognize LocalDate and LocalDateTime in javaTypeToSqlTypeMap and as a result they get categorized as UNKOWN_TYPE.
LocalDate and LocalDateTime have been available for years and we should try to include them in the framework.
The text was updated successfully, but these errors were encountered: