10
10
import java .time .LocalDate ;
11
11
import java .time .LocalDateTime ;
12
12
import java .time .LocalTime ;
13
+ import java .time .OffsetDateTime ;
13
14
import java .time .temporal .ChronoUnit ;
14
15
15
16
import org .hibernate .cfg .MappingSettings ;
19
20
import org .hibernate .dialect .Dialect ;
20
21
import org .hibernate .dialect .HANADialect ;
21
22
import org .hibernate .dialect .OracleDialect ;
23
+ import org .hibernate .dialect .PostgreSQLDialect ;
22
24
import org .hibernate .dialect .SybaseDialect ;
23
25
import org .hibernate .mapping .BasicValue ;
24
26
import org .hibernate .mapping .PersistentClass ;
31
33
32
34
import org .hibernate .testing .orm .junit .DomainModel ;
33
35
import org .hibernate .testing .orm .junit .DomainModelScope ;
36
+ import org .hibernate .testing .orm .junit .RequiresDialect ;
34
37
import org .hibernate .testing .orm .junit .ServiceRegistry ;
35
38
import org .hibernate .testing .orm .junit .SessionFactory ;
36
39
import org .hibernate .testing .orm .junit .SessionFactoryScope ;
@@ -204,6 +207,23 @@ void testLocalTime(SessionFactoryScope scope) {
204
207
} );
205
208
}
206
209
210
+ @ Test
211
+ @ RequiresDialect (value = PostgreSQLDialect .class )
212
+ void testArray (SessionFactoryScope scope ) {
213
+ final var offsetDateTime = OffsetDateTime .parse ("1977-07-24T12:34:56+02:00" );
214
+ scope .inTransaction ( session -> {
215
+ final var nativeQuery = session .createNativeQuery (
216
+ "WITH data AS (SELECT unnest(?) AS id, unnest(?) AS offset_date_time)"
217
+ + " INSERT INTO EntityWithJavaTimeValues (id, theOffsetDateTime) SELECT * FROM data"
218
+ );
219
+ nativeQuery .setParameter ( 1 , new int [] { 1 } );
220
+ nativeQuery .setParameter ( 2 , new OffsetDateTime [] { offsetDateTime } );
221
+ assertThat ( nativeQuery .executeUpdate () ).isEqualTo ( 1 );
222
+ final var found = session .find ( EntityWithJavaTimeValues .class , 1 );
223
+ assertThat ( found .theOffsetDateTime .toInstant () ).isEqualTo ( offsetDateTime .toInstant () );
224
+ } );
225
+ }
226
+
207
227
@ AfterEach
208
228
void dropTestData (SessionFactoryScope scope ) {
209
229
scope .inTransaction ( (session ) -> {
@@ -218,6 +238,8 @@ public static class EntityWithJavaTimeValues {
218
238
private Integer id ;
219
239
private String name ;
220
240
241
+ private OffsetDateTime theOffsetDateTime ;
242
+
221
243
private Instant theInstant ;
222
244
223
245
private LocalDateTime theLocalDateTime ;
0 commit comments