Skip to content

Commit 32626b2

Browse files
committed
HHH-18589 Properly handle temporals in BC era
1 parent 513bbb7 commit 32626b2

19 files changed

+1015
-211
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/CockroachLegacyDialect.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,11 @@
129129
import static org.hibernate.type.SqlTypes.UUID;
130130
import static org.hibernate.type.SqlTypes.VARBINARY;
131131
import static org.hibernate.type.SqlTypes.VARCHAR;
132-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
132+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDateWithEra;
133133
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
134134
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
135-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
136-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
135+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicrosAndEra;
136+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillisAndEra;
137137

138138
/**
139139
* A {@linkplain Dialect SQL dialect} for CockroachDB.
@@ -742,7 +742,7 @@ public void appendDateTimeLiteral(
742742
switch ( precision ) {
743743
case DATE:
744744
appender.appendSql( "date '" );
745-
appendAsDate( appender, temporalAccessor );
745+
appendAsDateWithEra( appender, temporalAccessor );
746746
appender.appendSql( '\'' );
747747
break;
748748
case TIME:
@@ -759,12 +759,12 @@ public void appendDateTimeLiteral(
759759
case TIMESTAMP:
760760
if ( supportsTemporalLiteralOffset() && temporalAccessor.isSupported( ChronoField.OFFSET_SECONDS ) ) {
761761
appender.appendSql( "timestamp with time zone '" );
762-
appendAsTimestampWithMicros( appender, temporalAccessor, true, jdbcTimeZone );
762+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, true, jdbcTimeZone );
763763
appender.appendSql( '\'' );
764764
}
765765
else {
766766
appender.appendSql( "timestamp '" );
767-
appendAsTimestampWithMicros( appender, temporalAccessor, false, jdbcTimeZone );
767+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, false, jdbcTimeZone );
768768
appender.appendSql( '\'' );
769769
}
770770
break;
@@ -778,7 +778,7 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType
778778
switch ( precision ) {
779779
case DATE:
780780
appender.appendSql( "date '" );
781-
appendAsDate( appender, date );
781+
appendAsDateWithEra( appender, date );
782782
appender.appendSql( '\'' );
783783
break;
784784
case TIME:
@@ -788,7 +788,7 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType
788788
break;
789789
case TIMESTAMP:
790790
appender.appendSql( "timestamp with time zone '" );
791-
appendAsTimestampWithMicros( appender,date, jdbcTimeZone );
791+
appendAsTimestampWithMicrosAndEra( appender,date, jdbcTimeZone );
792792
appender.appendSql( '\'' );
793793
break;
794794
default:
@@ -805,7 +805,7 @@ public void appendDateTimeLiteral(
805805
switch ( precision ) {
806806
case DATE:
807807
appender.appendSql( "date '" );
808-
appendAsDate( appender, calendar );
808+
appendAsDateWithEra( appender, calendar );
809809
appender.appendSql( '\'' );
810810
break;
811811
case TIME:
@@ -815,7 +815,7 @@ public void appendDateTimeLiteral(
815815
break;
816816
case TIMESTAMP:
817817
appender.appendSql( "timestamp with time zone '" );
818-
appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone );
818+
appendAsTimestampWithMillisAndEra( appender, calendar, jdbcTimeZone );
819819
appender.appendSql( '\'' );
820820
break;
821821
default:

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/H2LegacyDialect.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorNoOpImpl;
7979
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
8080
import org.hibernate.type.descriptor.jdbc.EnumJdbcType;
81+
import org.hibernate.type.descriptor.jdbc.GregorianEpochBasedDateJdbcType;
82+
import org.hibernate.type.descriptor.jdbc.GregorianEpochBasedTimestampJdbcType;
8183
import org.hibernate.type.descriptor.jdbc.JdbcType;
8284
import org.hibernate.type.descriptor.jdbc.OrdinalEnumJdbcType;
8385
import org.hibernate.type.descriptor.jdbc.TimeAsTimestampWithTimeZoneJdbcType;
@@ -294,6 +296,8 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
294296
jdbcTypeRegistry.addDescriptor( TimeUtcAsOffsetTimeJdbcType.INSTANCE );
295297
}
296298
jdbcTypeRegistry.addDescriptor( TIMESTAMP_UTC, TimestampUtcAsInstantJdbcType.INSTANCE );
299+
jdbcTypeRegistry.addDescriptor( GregorianEpochBasedDateJdbcType.INSTANCE );
300+
jdbcTypeRegistry.addDescriptor( GregorianEpochBasedTimestampJdbcType.INSTANCE );
297301
if ( getVersion().isSameOrAfter( 1, 4, 197 ) ) {
298302
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
299303
}

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/PostgreSQLLegacyDialect.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,11 @@
158158
import static org.hibernate.type.SqlTypes.UUID;
159159
import static org.hibernate.type.SqlTypes.VARBINARY;
160160
import static org.hibernate.type.SqlTypes.VARCHAR;
161-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
161+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDateWithEra;
162162
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
163163
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
164-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
165-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
164+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicrosAndEra;
165+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillisAndEra;
166166

167167
/**
168168
* A {@linkplain Dialect SQL dialect} for PostgreSQL 8 and above.
@@ -1253,7 +1253,7 @@ public void appendDateTimeLiteral(
12531253
switch ( precision ) {
12541254
case DATE:
12551255
appender.appendSql( "date '" );
1256-
appendAsDate( appender, temporalAccessor );
1256+
appendAsDateWithEra( appender, temporalAccessor );
12571257
appender.appendSql( '\'' );
12581258
break;
12591259
case TIME:
@@ -1270,12 +1270,12 @@ public void appendDateTimeLiteral(
12701270
case TIMESTAMP:
12711271
if ( supportsTemporalLiteralOffset() && temporalAccessor.isSupported( ChronoField.OFFSET_SECONDS ) ) {
12721272
appender.appendSql( "timestamp with time zone '" );
1273-
appendAsTimestampWithMicros( appender, temporalAccessor, true, jdbcTimeZone );
1273+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, true, jdbcTimeZone );
12741274
appender.appendSql( '\'' );
12751275
}
12761276
else {
12771277
appender.appendSql( "timestamp '" );
1278-
appendAsTimestampWithMicros( appender, temporalAccessor, false, jdbcTimeZone );
1278+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, false, jdbcTimeZone );
12791279
appender.appendSql( '\'' );
12801280
}
12811281
break;
@@ -1289,7 +1289,7 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType
12891289
switch ( precision ) {
12901290
case DATE:
12911291
appender.appendSql( "date '" );
1292-
appendAsDate( appender, date );
1292+
appendAsDateWithEra( appender, date );
12931293
appender.appendSql( '\'' );
12941294
break;
12951295
case TIME:
@@ -1299,7 +1299,7 @@ public void appendDateTimeLiteral(SqlAppender appender, Date date, TemporalType
12991299
break;
13001300
case TIMESTAMP:
13011301
appender.appendSql( "timestamp with time zone '" );
1302-
appendAsTimestampWithMicros( appender, date, jdbcTimeZone );
1302+
appendAsTimestampWithMicrosAndEra( appender, date, jdbcTimeZone );
13031303
appender.appendSql( '\'' );
13041304
break;
13051305
default:
@@ -1316,7 +1316,7 @@ public void appendDateTimeLiteral(
13161316
switch ( precision ) {
13171317
case DATE:
13181318
appender.appendSql( "date '" );
1319-
appendAsDate( appender, calendar );
1319+
appendAsDateWithEra( appender, calendar );
13201320
appender.appendSql( '\'' );
13211321
break;
13221322
case TIME:
@@ -1326,7 +1326,7 @@ public void appendDateTimeLiteral(
13261326
break;
13271327
case TIMESTAMP:
13281328
appender.appendSql( "timestamp with time zone '" );
1329-
appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone );
1329+
appendAsTimestampWithMillisAndEra( appender, calendar, jdbcTimeZone );
13301330
appender.appendSql( '\'' );
13311331
break;
13321332
default:

hibernate-core/src/main/java/org/hibernate/dialect/CockroachDialect.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@
124124
import static org.hibernate.type.SqlTypes.UUID;
125125
import static org.hibernate.type.SqlTypes.VARBINARY;
126126
import static org.hibernate.type.SqlTypes.VARCHAR;
127-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
127+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDateWithEra;
128128
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
129129
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
130-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
131-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
130+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicrosAndEra;
131+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillisAndEra;
132132

133133
/**
134134
* A {@linkplain Dialect SQL dialect} for CockroachDB 23.1 and above.
@@ -709,7 +709,7 @@ public void appendDateTimeLiteral(
709709
switch ( precision ) {
710710
case DATE:
711711
appender.appendSql( "date '" );
712-
appendAsDate( appender, temporalAccessor );
712+
appendAsDateWithEra( appender, temporalAccessor );
713713
appender.appendSql( '\'' );
714714
break;
715715
case TIME:
@@ -726,12 +726,12 @@ public void appendDateTimeLiteral(
726726
case TIMESTAMP:
727727
if ( supportsTemporalLiteralOffset() && temporalAccessor.isSupported( ChronoField.OFFSET_SECONDS ) ) {
728728
appender.appendSql( "timestamp with time zone '" );
729-
appendAsTimestampWithMicros( appender, temporalAccessor, true, jdbcTimeZone );
729+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, true, jdbcTimeZone );
730730
appender.appendSql( '\'' );
731731
}
732732
else {
733733
appender.appendSql( "timestamp '" );
734-
appendAsTimestampWithMicros( appender, temporalAccessor, false, jdbcTimeZone );
734+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, false, jdbcTimeZone );
735735
appender.appendSql( '\'' );
736736
}
737737
break;
@@ -750,7 +750,7 @@ public void appendDateTimeLiteral(
750750
switch ( precision ) {
751751
case DATE:
752752
appender.appendSql( "date '" );
753-
appendAsDate( appender, date );
753+
appendAsDateWithEra( appender, date );
754754
appender.appendSql( '\'' );
755755
break;
756756
case TIME:
@@ -760,7 +760,7 @@ public void appendDateTimeLiteral(
760760
break;
761761
case TIMESTAMP:
762762
appender.appendSql( "timestamp with time zone '" );
763-
appendAsTimestampWithMicros( appender,date, jdbcTimeZone );
763+
appendAsTimestampWithMicrosAndEra( appender,date, jdbcTimeZone );
764764
appender.appendSql( '\'' );
765765
break;
766766
default:
@@ -778,7 +778,7 @@ public void appendDateTimeLiteral(
778778
switch ( precision ) {
779779
case DATE:
780780
appender.appendSql( "date '" );
781-
appendAsDate( appender, calendar );
781+
appendAsDateWithEra( appender, calendar );
782782
appender.appendSql( '\'' );
783783
break;
784784
case TIME:
@@ -788,7 +788,7 @@ public void appendDateTimeLiteral(
788788
break;
789789
case TIMESTAMP:
790790
appender.appendSql( "timestamp with time zone '" );
791-
appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone );
791+
appendAsTimestampWithMillisAndEra( appender, calendar, jdbcTimeZone );
792792
appender.appendSql( '\'' );
793793
break;
794794
default:

hibernate-core/src/main/java/org/hibernate/dialect/H2Dialect.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
import org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl;
6868
import org.hibernate.tool.schema.extract.spi.SequenceInformationExtractor;
6969
import org.hibernate.type.descriptor.jdbc.EnumJdbcType;
70+
import org.hibernate.type.descriptor.jdbc.GregorianEpochBasedDateJdbcType;
71+
import org.hibernate.type.descriptor.jdbc.GregorianEpochBasedTimestampJdbcType;
7072
import org.hibernate.type.descriptor.jdbc.JdbcType;
7173
import org.hibernate.type.descriptor.jdbc.OrdinalEnumJdbcType;
7274
import org.hibernate.type.descriptor.jdbc.TimeUtcAsOffsetTimeJdbcType;
@@ -253,6 +255,8 @@ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry
253255
.getJdbcTypeRegistry();
254256
jdbcTypeRegistry.addDescriptor( TimeUtcAsOffsetTimeJdbcType.INSTANCE );
255257
jdbcTypeRegistry.addDescriptor( TimestampUtcAsInstantJdbcType.INSTANCE );
258+
jdbcTypeRegistry.addDescriptor( GregorianEpochBasedDateJdbcType.INSTANCE );
259+
jdbcTypeRegistry.addDescriptor( GregorianEpochBasedTimestampJdbcType.INSTANCE );
256260
jdbcTypeRegistry.addDescriptorIfAbsent( UUIDJdbcType.INSTANCE );
257261
jdbcTypeRegistry.addDescriptorIfAbsent( H2DurationIntervalSecondJdbcType.INSTANCE );
258262
jdbcTypeRegistry.addDescriptorIfAbsent( H2JsonJdbcType.INSTANCE );

hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,11 @@
151151
import static org.hibernate.type.SqlTypes.UUID;
152152
import static org.hibernate.type.SqlTypes.VARBINARY;
153153
import static org.hibernate.type.SqlTypes.VARCHAR;
154-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDate;
154+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsDateWithEra;
155155
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsLocalTime;
156156
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTime;
157-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicros;
158-
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillis;
157+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMicrosAndEra;
158+
import static org.hibernate.type.descriptor.DateTimeUtils.appendAsTimestampWithMillisAndEra;
159159

160160
/**
161161
* A {@linkplain Dialect SQL dialect} for PostgreSQL 13 and above.
@@ -1212,7 +1212,7 @@ public void appendDateTimeLiteral(
12121212
switch ( precision ) {
12131213
case DATE:
12141214
appender.appendSql( "date '" );
1215-
appendAsDate( appender, temporalAccessor );
1215+
appendAsDateWithEra( appender, temporalAccessor );
12161216
appender.appendSql( '\'' );
12171217
break;
12181218
case TIME:
@@ -1229,12 +1229,12 @@ public void appendDateTimeLiteral(
12291229
case TIMESTAMP:
12301230
if ( supportsTemporalLiteralOffset() && temporalAccessor.isSupported( ChronoField.OFFSET_SECONDS ) ) {
12311231
appender.appendSql( "timestamp with time zone '" );
1232-
appendAsTimestampWithMicros( appender, temporalAccessor, true, jdbcTimeZone );
1232+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, true, jdbcTimeZone );
12331233
appender.appendSql( '\'' );
12341234
}
12351235
else {
12361236
appender.appendSql( "timestamp '" );
1237-
appendAsTimestampWithMicros( appender, temporalAccessor, false, jdbcTimeZone );
1237+
appendAsTimestampWithMicrosAndEra( appender, temporalAccessor, false, jdbcTimeZone );
12381238
appender.appendSql( '\'' );
12391239
}
12401240
break;
@@ -1253,7 +1253,7 @@ public void appendDateTimeLiteral(
12531253
switch ( precision ) {
12541254
case DATE:
12551255
appender.appendSql( "date '" );
1256-
appendAsDate( appender, date );
1256+
appendAsDateWithEra( appender, date );
12571257
appender.appendSql( '\'' );
12581258
break;
12591259
case TIME:
@@ -1263,7 +1263,7 @@ public void appendDateTimeLiteral(
12631263
break;
12641264
case TIMESTAMP:
12651265
appender.appendSql( "timestamp with time zone '" );
1266-
appendAsTimestampWithMicros( appender, date, jdbcTimeZone );
1266+
appendAsTimestampWithMicrosAndEra( appender, date, jdbcTimeZone );
12671267
appender.appendSql( '\'' );
12681268
break;
12691269
default:
@@ -1281,7 +1281,7 @@ public void appendDateTimeLiteral(
12811281
switch ( precision ) {
12821282
case DATE:
12831283
appender.appendSql( "date '" );
1284-
appendAsDate( appender, calendar );
1284+
appendAsDateWithEra( appender, calendar );
12851285
appender.appendSql( '\'' );
12861286
break;
12871287
case TIME:
@@ -1291,7 +1291,7 @@ public void appendDateTimeLiteral(
12911291
break;
12921292
case TIMESTAMP:
12931293
appender.appendSql( "timestamp with time zone '" );
1294-
appendAsTimestampWithMillis( appender, calendar, jdbcTimeZone );
1294+
appendAsTimestampWithMillisAndEra( appender, calendar, jdbcTimeZone );
12951295
appender.appendSql( '\'' );
12961296
break;
12971297
default:

0 commit comments

Comments
 (0)