Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ protected String getElementTypeName(JavaType<?> javaType, SharedSessionContractI
.getSizeStrategy()
.resolveSize( elementJdbcType, elementJavaType, null, null, null );
final DdlTypeRegistry ddlTypeRegistry = session.getTypeConfiguration().getDdlTypeRegistry();
final String typeName = ddlTypeRegistry.getDescriptor( elementJdbcType.getDdlTypeCode() )
.getTypeName( size, new BasicTypeImpl<>( elementJavaType, elementJdbcType), ddlTypeRegistry );
int cutIndex = typeName.indexOf( '(' );
if ( cutIndex > 0 ) {
final String typeName =
ddlTypeRegistry.getDescriptor( elementJdbcType.getDdlTypeCode() )
.getTypeName( size, new BasicTypeImpl<>( elementJavaType, elementJdbcType), ddlTypeRegistry );

final int cutIndexBegin = typeName.indexOf( '(' );
if ( cutIndexBegin > 0 ) {
final int cutIndexEnd = typeName.lastIndexOf( ')' );
assert cutIndexEnd > cutIndexBegin;
// getTypeName for this case required length, etc, parameters.
// Cut them out and use database defaults.
return typeName.substring( 0, cutIndex );
// e.g. "timestamp($p) with timezone" becomes "timestamp with timezone"
return typeName.substring( 0, cutIndexBegin ) + typeName.substring( cutIndexEnd + 1 );
}
else {
return typeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;

import org.hibernate.cfg.MappingSettings;
Expand All @@ -19,6 +20,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.HANADialect;
import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.PersistentClass;
Expand All @@ -31,6 +33,7 @@

import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.RequiresDialect;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
Expand Down Expand Up @@ -204,6 +207,23 @@
} );
}

@Test
@RequiresDialect(value = PostgreSQLDialect.class)
void testArray(SessionFactoryScope scope) {
final var offsetDateTime = OffsetDateTime.parse("1977-07-24T12:34:56+02:00");
scope.inTransaction( session -> {
final var nativeQuery = session.createNativeQuery(
"WITH data AS (SELECT unnest(?) AS id, unnest(?) AS offset_date_time)"
+ " INSERT INTO EntityWithJavaTimeValues (id, theOffsetDateTime) SELECT * FROM data"
);
Comment on lines +215 to +218

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
QueryProducerImplementor.createNativeQuery
should be avoided because it has been deprecated.
nativeQuery.setParameter( 1, new int[] { 1 } );
nativeQuery.setParameter( 2, new OffsetDateTime[] { offsetDateTime } );
assertThat( nativeQuery.executeUpdate() ).isEqualTo( 1 );
final var found = session.find( EntityWithJavaTimeValues.class, 1 );
assertThat( found.theOffsetDateTime.toInstant() ).isEqualTo( offsetDateTime.toInstant() );
} );
}

@AfterEach
void dropTestData(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
Expand All @@ -218,6 +238,8 @@
private Integer id;
private String name;

private OffsetDateTime theOffsetDateTime;

private Instant theInstant;

private LocalDateTime theLocalDateTime;
Expand Down
Loading