369
369
import org .hibernate .sql .results .internal .StandardEntityGraphTraversalStateImpl ;
370
370
import org .hibernate .type .BasicType ;
371
371
import org .hibernate .type .JavaObjectType ;
372
+ import org .hibernate .type .NullType ;
372
373
import org .hibernate .type .SqlTypes ;
373
374
import org .hibernate .type .descriptor .java .BasicJavaType ;
374
375
import org .hibernate .type .descriptor .java .EnumJavaType ;
383
384
import org .jboss .logging .Logger ;
384
385
385
386
import jakarta .persistence .TemporalType ;
387
+ import jakarta .persistence .metamodel .SingularAttribute ;
388
+ import jakarta .persistence .metamodel .Type ;
386
389
387
390
import static org .hibernate .internal .util .NullnessHelper .coalesceSuppliedValues ;
388
391
import static org .hibernate .query .sqm .BinaryArithmeticOperator .ADD ;
@@ -4884,11 +4887,15 @@ else if ( paramType instanceof EntityDomainType ) {
4884
4887
paramSqmType .getExpressibleJavaType ().getJavaTypeClass ()
4885
4888
);
4886
4889
4887
- if ( basicTypeForJavaType == null && paramSqmType instanceof EntityDomainType ) {
4888
- final SimpleDomainType idType = ( (EntityDomainType ) paramSqmType ).getIdType ();
4889
- if ( idType != null ) {
4890
- return getTypeConfiguration ().getBasicTypeForJavaType (
4891
- idType .getExpressibleJavaType ().getJavaTypeClass () );
4890
+ if ( basicTypeForJavaType == null ) {
4891
+ if ( paramSqmType instanceof EntityDomainType ) {
4892
+ return getIdType ( (EntityDomainType ) paramSqmType );
4893
+ }
4894
+ else if ( paramSqmType instanceof SingularAttribute ) {
4895
+ final Type type = ( (SingularAttribute ) paramSqmType ).getType ();
4896
+ if ( type instanceof EntityDomainType ) {
4897
+ return getIdType ( (EntityDomainType ) type );
4898
+ }
4892
4899
}
4893
4900
}
4894
4901
@@ -4898,6 +4905,15 @@ else if ( paramType instanceof EntityDomainType ) {
4898
4905
throw new ConversionException ( "Could not determine ValueMapping for SqmParameter: " + sqmParameter );
4899
4906
}
4900
4907
4908
+ private BasicType getIdType (EntityDomainType entityDomainType ) {
4909
+ final SimpleDomainType idType = entityDomainType .getIdType ();
4910
+ if ( idType != null ) {
4911
+ return getTypeConfiguration ().getBasicTypeForJavaType (
4912
+ idType .getExpressibleJavaType ().getJavaTypeClass () );
4913
+ }
4914
+ return null ;
4915
+ }
4916
+
4901
4917
private void resolveSqmParameter (
4902
4918
SqmParameter <?> expression ,
4903
4919
MappingModelExpressible <?> valueMapping ,
@@ -4958,6 +4974,10 @@ else if ( bindValue instanceof BigDecimal ) {
4958
4974
}
4959
4975
}
4960
4976
if ( sqlTypedMapping == null ) {
4977
+ if ( bindable == null ) {
4978
+ throw new ConversionException (
4979
+ "Could not determine neither the SqlTypedMapping nor the Bindable value for SqmParameter: " + expression );
4980
+ }
4961
4981
bindable .forEachJdbcType (
4962
4982
(index , jdbcMapping ) -> jdbcParameterConsumer .accept (
4963
4983
index ,
0 commit comments