@@ -2971,17 +2971,23 @@ public SqmPath<?> visitEntityIdReference(HqlParser.EntityIdReferenceContext ctx)
2971
2971
2972
2972
final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
2973
2973
final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
2974
-
2975
2974
if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
2976
- final SqmPathSource <?> identifierDescriptor = ( (IdentifiableDomainType <?>) sqmPathType ).getIdentifierDescriptor ();
2975
+ final IdentifiableDomainType <?> identifiableType = (IdentifiableDomainType <?>) sqmPathType ;
2976
+ final SqmPathSource <?> identifierDescriptor = identifiableType .getIdentifierDescriptor ();
2977
+ if ( identifierDescriptor == null ) {
2978
+ // mainly for benefit of Hibernate Processor
2979
+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
2980
+ + "' of 'id()' is a '" + identifiableType .getTypeName ()
2981
+ + "' and does not have a well-defined '@Id' attribute" );
2982
+ }
2977
2983
return sqmPath .get ( identifierDescriptor .getPathName () );
2978
2984
}
2979
2985
else if ( sqmPath instanceof SqmAnyValuedSimplePath <?> ) {
2980
2986
return sqmPath .resolvePathPart ( AnyKeyPart .KEY_NAME , true , processingStateStack .getCurrent ().getCreationState () );
2981
2987
}
2982
2988
else {
2983
2989
throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
2984
- + "' of 'id()' function does not resolve to an entity type" );
2990
+ + "' of 'id()' does not resolve to an entity type" );
2985
2991
}
2986
2992
}
2987
2993
@@ -2994,26 +3000,22 @@ public SqmExpression<?> visitEntityVersionExpression(HqlParser.EntityVersionExpr
2994
3000
public SqmPath <?> visitEntityVersionReference (HqlParser .EntityVersionReferenceContext ctx ) {
2995
3001
final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
2996
3002
final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
2997
-
2998
3003
if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
2999
- @ SuppressWarnings ("unchecked" )
3000
- final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <Object >) sqmPathType ;
3001
- final SingularPersistentAttribute <Object , ?> versionAttribute = identifiableType .findVersionAttribute ();
3002
- if ( versionAttribute == null ) {
3003
- throw new FunctionArgumentException (
3004
- String .format (
3005
- "Argument '%s' of 'version()' function resolved to entity type '%s' which does not have a '@Version' attribute" ,
3006
- sqmPath .getNavigablePath (),
3007
- identifiableType .getTypeName ()
3008
- )
3009
- );
3004
+ final IdentifiableDomainType <?> identifiableType = (IdentifiableDomainType <?>) sqmPathType ;
3005
+ if ( !identifiableType .hasVersionAttribute () ) {
3006
+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3007
+ + "' of 'version()' is a '" + identifiableType .getTypeName ()
3008
+ + "' and does not have a '@Version' attribute" );
3010
3009
}
3011
-
3010
+ @ SuppressWarnings ("unchecked" )
3011
+ final SingularPersistentAttribute <Object , ?> versionAttribute =
3012
+ (SingularPersistentAttribute <Object , ?>) identifiableType .findVersionAttribute ();
3012
3013
return sqmPath .get ( versionAttribute );
3013
3014
}
3014
-
3015
- throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3016
- + "' of 'version()' function does not resolve to an entity type" );
3015
+ else {
3016
+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3017
+ + "' of 'version()' does not resolve to an entity type" );
3018
+ }
3017
3019
}
3018
3020
3019
3021
@ Override
@@ -3032,35 +3034,29 @@ public SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferen
3032
3034
3033
3035
if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
3034
3036
@ SuppressWarnings ("unchecked" )
3035
- final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <? super Object >) sqmPathType ;
3037
+ final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <Object >) sqmPathType ;
3036
3038
final List <? extends PersistentAttribute <Object , ?>> attributes = identifiableType .findNaturalIdAttributes ();
3037
3039
if ( attributes == null ) {
3038
- throw new FunctionArgumentException (
3039
- String .format (
3040
- "Argument '%s' of 'naturalid()' function resolved to entity type '%s' which does not have a natural id" ,
3041
- sqmPath .getNavigablePath (),
3042
- identifiableType .getTypeName ()
3043
- )
3040
+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3041
+ + "' of 'naturalid()' is a '" + identifiableType .getTypeName ()
3042
+ + "' and does not have a natural id"
3044
3043
);
3045
3044
}
3046
3045
else if ( attributes .size () >1 ) {
3047
- throw new FunctionArgumentException (
3048
- String .format (
3049
- "Argument '%s' of 'naturalid()' function resolved to entity type '%s' which has a composite natural id" ,
3050
- sqmPath .getNavigablePath (),
3051
- identifiableType .getTypeName ()
3052
- )
3046
+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3047
+ + "' of 'naturalid()' is a '" + identifiableType .getTypeName ()
3048
+ + "' and has a composite natural id"
3053
3049
);
3054
3050
}
3055
3051
3056
3052
@ SuppressWarnings ("unchecked" )
3057
- SingularAttribute <Object , ?> naturalIdAttribute
3053
+ final SingularAttribute <Object , ?> naturalIdAttribute
3058
3054
= (SingularAttribute <Object , ?>) attributes .get (0 );
3059
3055
return sqmPath .get ( naturalIdAttribute );
3060
3056
}
3061
3057
3062
3058
throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3063
- + "' of 'naturalid()' function does not resolve to an entity type" );
3059
+ + "' of 'naturalid()' does not resolve to an entity type" );
3064
3060
}
3065
3061
//
3066
3062
// @Override
0 commit comments