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

HHH-11773 - Add support for JDBC 4.2 type names #1940

Closed
wants to merge 1 commit into from

Conversation

vladmihalcea
Copy link
Contributor

@marschall
Copy link
Contributor

marschall commented Jun 20, 2017

Regarding database support in general you need up to date database drivers. To my knowledge the current situation is like this:

  • HSQLDB 2.4.0 supports it but has issues with literal parsing, this is fixed in 2.4.1 (not yet released)
  • Oracle needs ojdbc8-12.2.0.1
  • SQL Server as of 6.1.0.jre8 only supports #setObject(int, Object) but not #getObject(int, Class), however you can use proprietary APIs
  • H2 needs 1.4.194 (1.4.193 works in theory as well)
  • Postgres needs pgjdbc 9.4.1208 or later

This all comes from marschall/threeten-jpa#41 in this project.

To be fair I only use #setObject(int, Object) and not #setObject(int, Object, int) there, I believe that's where at least the H2 failures stem from.

@marschall
Copy link
Contributor

I created h2database/h2database#536 to fix the issue in H2.

@marschall
Copy link
Contributor

@vladmihalcea
Copy link
Contributor Author

We use the following drivers:

  • PostgreSQL 42.1.1 > 9.4.1208
  • H2 1.4.196 > 1.4.194
  • SQL Server 6.1.0.jre8, I added the datetime specific logic using Reflection
  • Oracle ojdbc7 12.1.0.2, I should upgrade to ojdbc8-12.2.0.1

I'll also try with #setObject(int, Object) as you suggested.

@vladmihalcea
Copy link
Contributor Author

I tried with #setObject(int, Object), but it only works better for PostgreSQL, and just for handling Timestamp, not Time.

I'll leave this PR open for a while hoping that JDBC drivers will better handle the new JDBC 4.2 timestamp and time with timezone types.

@marschall
Copy link
Contributor

I understand this decision. There exist work arounds for people who want to experiment.

Probably in time for the JPA 2.1 service release that's part of Java EE 8 this will have to be revisited, let's hope the situation improves until then. Speaking of which right now Hibernate implements support for LocalDateTime and LocalTime by converting through java.sql types. This is not optimal for two reasons

  1. LocalTime has nanosecond resolution java.sql.Time has millisecond resolution, converting results in silent data truncation.
  2. java.sql.Timestamp due to implementation details is affected by daylight savings time even though it shouldn't be. If you run your JVM in a time zone that has daylight savings time the following value can not be stored or loaded correctly when a conversion through java.sql.Timestamp happens. It can only be stored and loaded correctly when driver support for JSR-310 is used.
  private static LocalDateTime getUnstorableValue() {
    ZoneId systemTimezone = ZoneId.systemDefault();
    Instant now = Instant.now();

    ZoneRules rules = systemTimezone.getRules();
    ZoneOffsetTransition transition = rules.nextTransition(now);
    assertNotNull(transition);
    if (!transition.getDateTimeBefore().isBefore(transition.getDateTimeAfter())) {
      transition = rules.nextTransition(transition.getInstant().plusSeconds(1L));
      assertNotNull(transition);
    }

    Duration gap = Duration.between(transition.getDateTimeBefore(), transition.getDateTimeAfter());
    return transition.getDateTimeBefore().plus(gap.dividedBy(2L));
  }

Ultimately somebody has to make the first move, if drivers are waiting for frameworks to move first and frameworks are waiting for drivers to move first we end up in a chicken and egg situation see pgjdbc/pgjdbc#695

Yes OffsetTime support has not yet been implemented in pgjdbc.

@vladmihalcea
Copy link
Contributor Author

@dreab8 Andrea, check out the comment above about LocalTime and Timestamp. I guess we should open a Jira issue about it, right?

@dreab8
Copy link
Member

dreab8 commented Jun 22, 2017

Hi @vladmihalcea,
I have not a great experience on this topic, better to ask @sebersole for an opinion.

@vladmihalcea
Copy link
Contributor Author

vladmihalcea commented Jun 22, 2017

@abcfy2
Copy link

abcfy2 commented Jul 17, 2019

Any update for this pull request ? I think support Types.TIMESTAMP_WITH_TIMEZONE is very useful when I use OffsetDateTime and ZonedDateTime, but I find this pull request is still not merge.

Is hibernate still plan to support JDBC 4.2 type names ?

@marschall
Copy link
Contributor

@abcfy2 until fully supported you may find the threeten-jpa-jdbc42-hibernate subproject of https://github.com/marschall/threeten-jpa to be helpful. Pleas note that:

  • this requires driver support
  • this does not add support for DDL
  • ZonedDateTime only really works with Oracle

Base automatically changed from master to main March 19, 2021 15:59
@marschall
Copy link
Contributor

Was fixed in 2c80250 in 6.0.0. Can be closed.

@dreab8 dreab8 closed this Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants