HHH-15429 Fix loss of precision when serializing/deserializing arrays of doubles

This commit is contained in:
Christian Beikov 2022-08-03 13:40:06 +02:00
parent 4596c7f622
commit 23a487628a
2 changed files with 12 additions and 1 deletions

View File

@ -156,7 +156,7 @@ public class ArrayJdbcType implements JdbcType {
final TypeConfiguration typeConfiguration = options.getSessionFactory().getTypeConfiguration();
final JdbcType underlyingJdbcType = typeConfiguration.getJdbcTypeRegistry()
.getDescriptor( elementJdbcType.getDefaultSqlTypeCode() );
final Class<?> preferredJavaTypeClass = underlyingJdbcType.getPreferredJavaTypeClass( options );
final Class<?> preferredJavaTypeClass = elementJdbcType.getPreferredJavaTypeClass( options );
final Class<?> elementJdbcJavaTypeClass;
if ( preferredJavaTypeClass == null ) {
elementJdbcJavaTypeClass = underlyingJdbcType.getJdbcRecommendedJavaTypeMapping(

View File

@ -60,6 +60,17 @@ public class DoubleArrayTest extends BaseNonConfigCoreFunctionalTestCase {
q.setParameter( "id", 5L );
q.setParameter( "data", new Double[]{ null, null, 0.0 } );
q.executeUpdate();
em.persist( new TableWithDoubleArrays( 6L, new Double[]{ 0.12 } ) );
} );
}
@Test
public void testLoadValueWithInexactFloatRepresentation() {
inSession( em -> {
TableWithDoubleArrays tableRecord;
tableRecord = em.find( TableWithDoubleArrays.class, 6L );
assertThat( tableRecord.getTheArray(), is( new Double[]{ 0.12 } ) );
} );
}