HHH-17726 Add test for issue

This commit is contained in:
Marco Belladelli 2024-02-13 11:13:23 +01:00
parent b139d449c8
commit 3f60909967
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
3 changed files with 81 additions and 17 deletions

View File

@ -8,9 +8,6 @@ package org.hibernate.orm.test.mapping.basic;
import java.sql.Types;
import java.util.TimeZone;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
@ -19,10 +16,16 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@ -57,6 +60,25 @@ public class TimeZoneMappingTests {
);
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17726" )
public void testUpdateQuery(SessionFactoryScope scope) {
scope.inTransaction( session -> session.persist( new EntityWithTimeZone( 1, TimeZone.getDefault() ) ) );
scope.inTransaction( session -> {
final TimeZone timeZone = TimeZone.getTimeZone( "UTC" );
session.createMutationQuery( "update EntityWithTimeZone e set e.timeZone = :timeZone" )
.setParameter( "timeZone", timeZone )
.executeUpdate();
final EntityWithTimeZone entity = session.find( EntityWithTimeZone.class, 1 );
assertThat( entity.timeZone, equalTo( timeZone ) );
} );
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction( session -> session.createMutationQuery( "delete EntityWithTimeZone" ).executeUpdate() );
}
@Entity(name = "EntityWithTimeZone")
@Table(name = "EntityWithTimeZone")
public static class EntityWithTimeZone {

View File

@ -8,9 +8,6 @@ package org.hibernate.orm.test.mapping.basic;
import java.sql.Types;
import java.time.ZoneOffset;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.internal.BasicAttributeMapping;
@ -19,10 +16,16 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
@ -57,6 +60,28 @@ public class ZoneOffsetMappingTests {
);
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17726" )
public void testUpdateQuery(SessionFactoryScope scope) {
scope.inTransaction( session -> session.persist( new EntityWithZoneOffset(
1,
ZoneOffset.from( ZoneOffset.MIN )
) ) );
scope.inTransaction( session -> {
final ZoneOffset zoneOffset = ZoneOffset.from( ZoneOffset.UTC );
session.createMutationQuery( "update EntityWithZoneOffset e set e.zoneOffset = :zoneOffset" )
.setParameter( "zoneOffset", zoneOffset )
.executeUpdate();
final EntityWithZoneOffset entity = session.find( EntityWithZoneOffset.class, 1 );
assertThat( entity.zoneOffset, equalTo( zoneOffset ) );
} );
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction( session -> session.createMutationQuery( "delete EntityWithZoneOffset" ).executeUpdate() );
}
@Entity(name = "EntityWithZoneOffset")
@Table(name = "EntityWithZoneOffset")
public static class EntityWithZoneOffset {

View File

@ -18,10 +18,11 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.Jira;
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.AfterEach;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CollectionTable;
@ -70,18 +71,34 @@ public class ZoneMappingTests {
session.persist( entity3 );
} );
try {
scope.inTransaction( (session) -> {
session.createQuery( "from ZoneMappingTestEntity" ).list();
});
}
finally {
scope.inTransaction( (session) -> {
session.createQuery( "delete ZoneMappingTestEntity" ).executeUpdate();
});
}
scope.inTransaction( (session) -> session.createQuery( "from ZoneMappingTestEntity" ).list() );
}
@Test
@Jira( "https://hibernate.atlassian.net/browse/HHH-17726" )
public void testUpdateQuery(SessionFactoryScope scope) {
scope.inTransaction( session -> session.persist( new ZoneMappingTestEntity(
1,
"one",
ZoneId.systemDefault(),
ZoneOffset.MIN
) ) );
scope.inTransaction( session -> {
final ZoneId zoneId = ZoneId.of( "UTC" );
final ZoneOffset zoneOffset = ZoneOffset.from( ZoneOffset.UTC );
session.createMutationQuery(
"update ZoneMappingTestEntity e set e.zoneId = :zoneId, e.zoneOffset = :zoneOffset"
).setParameter( "zoneId", zoneId ).setParameter( "zoneOffset", zoneOffset ).executeUpdate();
final ZoneMappingTestEntity entity = session.find( ZoneMappingTestEntity.class, 1 );
assertThat( entity.getZoneId() ).isEqualTo( zoneId );
assertThat( entity.getZoneOffset() ).isEqualTo( zoneOffset );
} );
}
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction( session -> session.createMutationQuery( "delete ZoneMappingTestEntity" ).executeUpdate() );
}
@Entity( name = "ZoneMappingTestEntity" )
@Table( name = "zone_map_test_entity" )