HHH-15361 Fix update assignment issues due to missing JavaType#isWider impls

This commit is contained in:
Christian Beikov 2022-06-24 00:02:22 +02:00
parent 0864ca58a3
commit 0777f7941c
10 changed files with 101 additions and 1 deletions

View File

@ -133,6 +133,16 @@ public class CalendarDateJavaType extends AbstractTemporalJavaType<Calendar> {
return cal;
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Date":
return true;
default:
return false;
}
}
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
return dialect.getDefaultTimestampPrecision();

View File

@ -151,6 +151,18 @@ public class CalendarJavaType extends AbstractTemporalJavaType<Calendar> impleme
return cal;
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.util.Date":
case "java.sql.Date":
case "java.sql.Timestamp":
return true;
default:
return false;
}
}
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
return dialect.getDefaultTimestampPrecision();

View File

@ -133,6 +133,16 @@ public class CalendarTimeJavaType extends AbstractTemporalJavaType<Calendar> {
return cal;
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Time":
return true;
default:
return false;
}
}
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
return 0; //seconds (currently ignored since Dialects don't parameterize time type by precision)

View File

@ -165,6 +165,18 @@ public class DateJavaType extends AbstractTemporalJavaType<Date> implements Vers
throw unknownWrap( value.getClass() );
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Date":
case "java.sql.Timestamp":
case "java.util.Calendar":
return true;
default:
return false;
}
}
@Override
public Date next(
Date current,

View File

@ -175,6 +175,19 @@ public class JdbcTimestampJavaType extends AbstractTemporalJavaType<Date> implem
throw unknownWrap( value.getClass() );
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Date":
case "java.sql.Timestamp":
case "java.util.Date":
case "java.util.Calendar":
return true;
default:
return false;
}
}
@Override
public String toString(Date value) {
return LITERAL_FORMATTER.format( value.toInstant() );

View File

@ -157,4 +157,14 @@ public class LocalDateJavaType extends AbstractTemporalJavaType<LocalDate> {
throw unknownWrap( value.getClass() );
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Date":
return true;
default:
return false;
}
}
}

View File

@ -157,6 +157,19 @@ public class LocalDateTimeJavaType extends AbstractTemporalJavaType<LocalDateTim
throw unknownWrap( value.getClass() );
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Date":
case "java.sql.Timestamp":
case "java.util.Date":
case "java.util.Calendar":
return true;
default:
return false;
}
}
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
return dialect.getDefaultTimestampPrecision();

View File

@ -146,6 +146,16 @@ public class LocalTimeJavaType extends AbstractTemporalJavaType<LocalTime> {
throw unknownWrap( value.getClass() );
}
@Override
public boolean isWider(JavaType<?> javaType) {
switch ( javaType.getJavaType().getTypeName() ) {
case "java.sql.Time":
return true;
default:
return false;
}
}
@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
return 0;

View File

@ -162,7 +162,7 @@ public class ImplicitSelectWithJoinTests {
public void prepareTestData(SessionFactoryScope scope) {
scope.inTransaction( (session) -> {
final Vendor vendor = new Vendor( 1, "Steve's Curios", "Acme Corp." );
final Product product = new Product( 10, UUID.randomUUID(), vendor );
final Product product = new Product( 10, UUID.fromString( "53886a8a-7082-4879-b430-25cb94415be8" ), vendor );
session.persist( vendor );
session.persist( product );
} );

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.sql.exec;
import org.hibernate.orm.test.mapping.SecondaryTableTests;
import org.hibernate.orm.test.mapping.inheritance.joined.JoinedInheritanceTest;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.domain.StandardDomainModel;
import org.hibernate.testing.orm.domain.gambit.BasicEntity;
import org.hibernate.testing.orm.junit.DomainModel;
@ -48,6 +49,15 @@ public class HqlUpdateExecutionTests {
);
}
@Test
@TestForIssue( jiraKey = "HHH-15361")
public void testSimpleUpdateAssignability(SessionFactoryScope scope) {
scope.inTransaction(
session -> session.createQuery( "update EntityOfBasics set theDate = current_date" )
.executeUpdate()
);
}
@Test
public void testSimpleUpdateWithData(SessionFactoryScope scope) {
scope.inTransaction(