From b8d26f829e7ae33ef93fb91c5517a5d07a056eac Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 6 Jan 2022 21:59:34 +0100 Subject: [PATCH] add a test for selecting a datetime literal seems to be causing problems in 2 dbs --- .../orm/test/query/hql/LiteralTests.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/LiteralTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/LiteralTests.java index 5b12ccbf77..9175cb40f2 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/LiteralTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/LiteralTests.java @@ -15,10 +15,18 @@ import org.junit.jupiter.api.Test; import java.math.BigDecimal; import java.math.BigInteger; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.Instant; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaTypeDescriptor; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; /** @@ -191,6 +199,37 @@ public class LiteralTests { ); } + @Test + public void testSelectDatetimeLiterals(SessionFactoryScope scope) { + scope.inTransaction( + session -> { + assertThat( session.createQuery( "select datetime 1999-07-23 23:59" ).getSingleResult(), + is( instanceOf(LocalDateTime.class) ) ); + assertThat( session.createQuery( "select date 1999-07-23" ).getSingleResult(), + is( instanceOf(LocalDate.class) ) ); + assertThat( session.createQuery( "select time 23:59" ).getSingleResult(), + is( instanceOf(LocalTime.class) ) ); + + assertThat( session.createQuery( "select local datetime" ).getSingleResult(), + is( instanceOf(LocalDateTime.class) ) ); + assertThat( session.createQuery( "select local date" ).getSingleResult(), + is( instanceOf(LocalDate.class) ) ); + assertThat( session.createQuery( "select local time" ).getSingleResult(), + is( instanceOf(LocalTime.class) ) ); + + assertThat( session.createQuery( "select instant" ).getSingleResult(), + is( instanceOf(Instant.class) ) ); + + assertThat( session.createQuery( "select current timestamp" ).getSingleResult(), + is( instanceOf(Timestamp.class) ) ); + assertThat( session.createQuery( "select current date" ).getSingleResult(), + is( instanceOf(Date.class) ) ); + assertThat( session.createQuery( "select current time" ).getSingleResult(), + is( instanceOf(Time.class) ) ); + } + ); + } + @Test public void testBooleanLiteral(SessionFactoryScope scope) { scope.inTransaction(