Fix java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year when calling JdbcDateJavaTypeDescriptor#toString()
This commit is contained in:
parent
47593f6412
commit
98a00ea9a1
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue