Fix java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year when calling JdbcDateJavaTypeDescriptor#toString()

This commit is contained in:
Andrea Boriero 2021-10-28 14:43:51 +02:00 committed by Andrea Boriero
parent 47593f6412
commit 98a00ea9a1
2 changed files with 22 additions and 11 deletions

View File

@ -42,16 +42,6 @@ public class JdbcDateJavaTypeDescriptor extends AbstractTemporalJavaTypeDescript
@SuppressWarnings("unused")
public static final DateTimeFormatter LITERAL_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE;
/**
* Alias for {@link DateTimeFormatter#ISO_LOCAL_DATE}.
*
* Intended for use with logging
*
* @see #LITERAL_FORMATTER
*/
@SuppressWarnings({"unused", "WeakerAccess"})
public static final DateTimeFormatter LOGGABLE_FORMATTER = DateTimeFormatter.ISO_LOCAL_DATE;
public static class DateMutabilityPlan extends MutableMutabilityPlan<Date> {
public static final DateMutabilityPlan INSTANCE = new DateMutabilityPlan();
@Override
@ -85,7 +75,7 @@ public class JdbcDateJavaTypeDescriptor extends AbstractTemporalJavaTypeDescript
@Override
public String toString(Date value) {
return LOGGABLE_FORMATTER.format( value.toInstant() );
return new SimpleDateFormat( DATE_FORMAT ).format( value );
}
@Override

View File

@ -0,0 +1,21 @@
package org.hibernate.orm.test.type.descriptor.java;
import java.util.Date;
import org.hibernate.type.descriptor.java.JdbcDateJavaTypeDescriptor;
import org.hibernate.testing.orm.junit.BaseUnitTest;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
@BaseUnitTest
public class JdbcDateJavaTypeDescriptorTest {
@Test
public void testToString() {
final JdbcDateJavaTypeDescriptor javaTypeDescriptor = JdbcDateJavaTypeDescriptor.INSTANCE;
final String actual = javaTypeDescriptor.toString( new Date( 0 ) );
assertEquals( "01 January 1970", actual );
}
}