@@ -2971,17 +2971,23 @@ public SqmPath<?> visitEntityIdReference(HqlParser.EntityIdReferenceContext ctx)
29712971
29722972 final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
29732973 final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
2974-
29752974 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+ }
29772983 return sqmPath .get ( identifierDescriptor .getPathName () );
29782984 }
29792985 else if ( sqmPath instanceof SqmAnyValuedSimplePath <?> ) {
29802986 return sqmPath .resolvePathPart ( AnyKeyPart .KEY_NAME , true , processingStateStack .getCurrent ().getCreationState () );
29812987 }
29822988 else {
29832989 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" );
29852991 }
29862992 }
29872993
@@ -2994,26 +3000,22 @@ public SqmExpression<?> visitEntityVersionExpression(HqlParser.EntityVersionExpr
29943000 public SqmPath <?> visitEntityVersionReference (HqlParser .EntityVersionReferenceContext ctx ) {
29953001 final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
29963002 final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
2997-
29983003 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" );
30103009 }
3011-
3010+ @ SuppressWarnings ("unchecked" )
3011+ final SingularPersistentAttribute <Object , ?> versionAttribute =
3012+ (SingularPersistentAttribute <Object , ?>) identifiableType .findVersionAttribute ();
30123013 return sqmPath .get ( versionAttribute );
30133014 }
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+ }
30173019 }
30183020
30193021 @ Override
@@ -3032,35 +3034,29 @@ public SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferen
30323034
30333035 if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
30343036 @ SuppressWarnings ("unchecked" )
3035- final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <? super Object >) sqmPathType ;
3037+ final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <Object >) sqmPathType ;
30363038 final List <? extends PersistentAttribute <Object , ?>> attributes = identifiableType .findNaturalIdAttributes ();
30373039 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"
30443043 );
30453044 }
30463045 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"
30533049 );
30543050 }
30553051
30563052 @ SuppressWarnings ("unchecked" )
3057- SingularAttribute <Object , ?> naturalIdAttribute
3053+ final SingularAttribute <Object , ?> naturalIdAttribute
30583054 = (SingularAttribute <Object , ?>) attributes .get (0 );
30593055 return sqmPath .get ( naturalIdAttribute );
30603056 }
30613057
30623058 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" );
30643060 }
30653061//
30663062// @Override
0 commit comments