@@ -2999,17 +2999,22 @@ public SqmPath<?> visitEntityIdReference(HqlParser.EntityIdReferenceContext ctx)
29992999
30003000 final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
30013001 final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
3002-
3003- if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
3004- final SqmPathSource <?> identifierDescriptor = ( (IdentifiableDomainType <?>) sqmPathType ).getIdentifierDescriptor ();
3002+ if ( sqmPathType instanceof IdentifiableDomainType <?> identifiableType ) {
3003+ final SqmPathSource <?> identifierDescriptor = identifiableType .getIdentifierDescriptor ();
3004+ if ( identifierDescriptor == null ) {
3005+ // mainly for benefit of Hibernate Processor
3006+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3007+ + "' of 'id()' is a '" + identifiableType .getTypeName ()
3008+ + "' and does not have a well-defined '@Id' attribute" );
3009+ }
30053010 return sqmPath .get ( identifierDescriptor .getPathName () );
30063011 }
30073012 else if ( sqmPath instanceof SqmAnyValuedSimplePath <?> ) {
30083013 return sqmPath .resolvePathPart ( AnyKeyPart .KEY_NAME , true , processingStateStack .getCurrent ().getCreationState () );
30093014 }
30103015 else {
30113016 throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3012- + "' of 'id()' function does not resolve to an entity type" );
3017+ + "' of 'id()' does not resolve to an entity type" );
30133018 }
30143019 }
30153020
@@ -3022,26 +3027,21 @@ public SqmExpression<?> visitEntityVersionExpression(HqlParser.EntityVersionExpr
30223027 public SqmPath <?> visitEntityVersionReference (HqlParser .EntityVersionReferenceContext ctx ) {
30233028 final SqmPath <?> sqmPath = consumeDomainPath ( ctx .path () );
30243029 final DomainType <?> sqmPathType = sqmPath .getReferencedPathSource ().getSqmPathType ();
3025-
3026- if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
3027- @ SuppressWarnings ("unchecked" )
3028- final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <Object >) sqmPathType ;
3029- final SingularPersistentAttribute <Object , ?> versionAttribute = identifiableType .findVersionAttribute ();
3030- if ( versionAttribute == null ) {
3031- throw new FunctionArgumentException (
3032- String .format (
3033- "Argument '%s' of 'version()' function resolved to entity type '%s' which does not have a '@Version' attribute" ,
3034- sqmPath .getNavigablePath (),
3035- identifiableType .getTypeName ()
3036- )
3037- );
3030+ if ( sqmPathType instanceof IdentifiableDomainType <?> identifiableType ) {
3031+ if ( !identifiableType .hasVersionAttribute () ) {
3032+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3033+ + "' of 'version()' is a '" + identifiableType .getTypeName ()
3034+ + "' and does not have a '@Version' attribute" );
30383035 }
3039-
3036+ @ SuppressWarnings ("unchecked" )
3037+ final SingularPersistentAttribute <Object , ?> versionAttribute =
3038+ (SingularPersistentAttribute <Object , ?>) identifiableType .findVersionAttribute ();
30403039 return sqmPath .get ( versionAttribute );
30413040 }
3042-
3043- throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3044- + "' of 'version()' function does not resolve to an entity type" );
3041+ else {
3042+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3043+ + "' of 'version()' does not resolve to an entity type" );
3044+ }
30453045 }
30463046
30473047 @ Override
@@ -3060,35 +3060,29 @@ public SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferen
30603060
30613061 if ( sqmPathType instanceof IdentifiableDomainType <?> ) {
30623062 @ SuppressWarnings ("unchecked" )
3063- final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <? super Object >) sqmPathType ;
3063+ final IdentifiableDomainType <Object > identifiableType = (IdentifiableDomainType <Object >) sqmPathType ;
30643064 final List <? extends PersistentAttribute <Object , ?>> attributes = identifiableType .findNaturalIdAttributes ();
30653065 if ( attributes == null ) {
3066- throw new FunctionArgumentException (
3067- String .format (
3068- "Argument '%s' of 'naturalid()' function resolved to entity type '%s' which does not have a natural id" ,
3069- sqmPath .getNavigablePath (),
3070- identifiableType .getTypeName ()
3071- )
3066+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3067+ + "' of 'naturalid()' is a '" + identifiableType .getTypeName ()
3068+ + "' and does not have a natural id"
30723069 );
30733070 }
30743071 else if ( attributes .size () >1 ) {
3075- throw new FunctionArgumentException (
3076- String .format (
3077- "Argument '%s' of 'naturalid()' function resolved to entity type '%s' which has a composite natural id" ,
3078- sqmPath .getNavigablePath (),
3079- identifiableType .getTypeName ()
3080- )
3072+ throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3073+ + "' of 'naturalid()' is a '" + identifiableType .getTypeName ()
3074+ + "' and has a composite natural id"
30813075 );
30823076 }
30833077
30843078 @ SuppressWarnings ("unchecked" )
3085- SingularAttribute <Object , ?> naturalIdAttribute
3079+ final SingularAttribute <Object , ?> naturalIdAttribute
30863080 = (SingularAttribute <Object , ?>) attributes .get (0 );
30873081 return sqmPath .get ( naturalIdAttribute );
30883082 }
30893083
30903084 throw new FunctionArgumentException ( "Argument '" + sqmPath .getNavigablePath ()
3091- + "' of 'naturalid()' function does not resolve to an entity type" );
3085+ + "' of 'naturalid()' does not resolve to an entity type" );
30923086 }
30933087//
30943088// @Override
0 commit comments