HHH-14905 - Verify that custom JavaType and JdbcType registration combo works
This commit is contained in:
parent
31eb3b82c5
commit
0b46966096
|
@ -9,6 +9,7 @@ package org.hibernate.sql.exec.internal;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
import org.hibernate.mapping.IndexedConsumer;
|
import org.hibernate.mapping.IndexedConsumer;
|
||||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||||
|
@ -25,6 +26,7 @@ import org.hibernate.sql.exec.spi.JdbcParameterBindings;
|
||||||
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
import org.hibernate.sql.results.internal.SqlSelectionImpl;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.descriptor.java.JavaType;
|
import org.hibernate.type.descriptor.java.JavaType;
|
||||||
|
import org.hibernate.type.descriptor.jdbc.JdbcType;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,13 +112,29 @@ public abstract class AbstractJdbcParameter
|
||||||
else {
|
else {
|
||||||
valueClass = binding.getBindValue().getClass();
|
valueClass = binding.getBindValue().getClass();
|
||||||
}
|
}
|
||||||
final BasicType<?> basicType = executionContext.getSession()
|
|
||||||
.getFactory()
|
|
||||||
.getTypeConfiguration()
|
|
||||||
.getBasicTypeRegistry()
|
|
||||||
.getRegisteredType( valueClass );
|
|
||||||
|
|
||||||
return basicType.getJdbcMapping();
|
final SessionFactoryImplementor factory = executionContext.getSession().getFactory();
|
||||||
|
final TypeConfiguration typeConfiguration = factory.getTypeConfiguration();
|
||||||
|
|
||||||
|
final BasicType<?> basicType = typeConfiguration.getBasicTypeRegistry().getRegisteredType( valueClass );
|
||||||
|
if ( basicType != null ) {
|
||||||
|
return basicType.getJdbcMapping();
|
||||||
|
}
|
||||||
|
|
||||||
|
final BasicType<?> defaultForJavaType = typeConfiguration.getBasicTypeForJavaType( valueClass );
|
||||||
|
if ( defaultForJavaType != null ) {
|
||||||
|
return defaultForJavaType;
|
||||||
|
}
|
||||||
|
|
||||||
|
final JavaType<Object> javaType = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( valueClass );
|
||||||
|
if ( javaType != null ) {
|
||||||
|
final JdbcType recommendedJdbcType = javaType.getRecommendedJdbcType( typeConfiguration.getCurrentBaseSqlTypeIndicators() );
|
||||||
|
if ( recommendedJdbcType != null ) {
|
||||||
|
return typeConfiguration.getBasicTypeRegistry().resolve( javaType, recommendedJdbcType );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,6 +18,8 @@ import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import org.assertj.core.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +44,15 @@ public class StringArrayContributorTests {
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAsQueryParameter(SessionFactoryScope scope) {
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
|
session.createQuery( "select p from Post p where array_contains(:arr, p.title) = true" )
|
||||||
|
.setParameter( "arr", Arrays.array( "a", "b" ) )
|
||||||
|
.list();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void dropTestData(SessionFactoryScope scope) {
|
public void dropTestData(SessionFactoryScope scope) {
|
||||||
scope.inTransaction( (session) -> session.createQuery( "delete Post" ).executeUpdate() );
|
scope.inTransaction( (session) -> session.createQuery( "delete Post" ).executeUpdate() );
|
||||||
|
|
Loading…
Reference in New Issue