HHH-18201 - Test case
Executing query comparing instant field with parameter (set to instant value) increased by duration Executing query comparing local date field with parameter (set to local date value) increased by duration Executing query comparing duration field with parameter (set to duration value) increased by duration
This commit is contained in:
parent
c5cbe20bd1
commit
ca581e74f4
|
@ -0,0 +1,86 @@
|
|||
package org.hibernate.orm.test.query;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@DomainModel(annotatedClasses = TemporalParameterPlusDurationTest.SimpleEntity.class)
|
||||
@SessionFactory
|
||||
@JiraKey("HHH-18201")
|
||||
public class TemporalParameterPlusDurationTest {
|
||||
|
||||
@Test
|
||||
void timestampVsTimestampParameterPlusDuration(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where inst > :i + 1 second + 2 second", SimpleEntity.class )
|
||||
.setParameter( "i", Instant.now() )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
void timestampParameterPlusDurationVsTimestamp(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where :i + 1 second + 2 second > inst", SimpleEntity.class )
|
||||
.setParameter( "i", Instant.now() )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
void dateVsDateParameterPlusDuration(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where ldate > :i + 3 day + 2 day", SimpleEntity.class )
|
||||
.setParameter( "i", LocalDate.now() )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
void dateParameterPlusDurationVsDate(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where :i + 3 day + 2 day > ldate", SimpleEntity.class )
|
||||
.setParameter( "i", LocalDate.now() )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
void durationVsDurationParameterPlusDuration(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where dur > :i + 1 second", Number.class )
|
||||
.setParameter( "i", Duration.ofMinutes( 1 ) )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
void durationParameterVsDurationPlusDuration(SessionFactoryScope scope) {
|
||||
scope.inSession( session -> {
|
||||
session.createQuery( "select count(*) from SimpleEntity where :i + 1 second > dur", Number.class )
|
||||
.setParameter( "i", Duration.ofMinutes( 1 ) )
|
||||
.getResultCount();
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "SimpleEntity")
|
||||
public static class SimpleEntity {
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
Instant inst;
|
||||
|
||||
LocalDate ldate;
|
||||
|
||||
Duration dur;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue