@@ -423,7 +423,10 @@ public SqmInsertStatement<R> visitInsertStatement(HqlParser.InsertStatementConte
423
423
final SqmRoot <R > root = visitTargetEntity ( dmlTargetContext );
424
424
if ( root .getReferencedPathSource () instanceof SqmPolymorphicRootDescriptor <?> ) {
425
425
throw new SemanticException (
426
- "Can't create an INSERT for a non entity name: " + root .getReferencedPathSource ().getHibernateEntityName ()
426
+ String .format (
427
+ "Target type '%s' in insert statement is not an entity" ,
428
+ root .getReferencedPathSource ().getHibernateEntityName ()
429
+ )
427
430
);
428
431
}
429
432
@@ -511,7 +514,10 @@ public SqmUpdateStatement<R> visitUpdateStatement(HqlParser.UpdateStatementConte
511
514
final SqmRoot <R > root = visitTargetEntity ( dmlTargetContext );
512
515
if ( root .getReferencedPathSource () instanceof SqmPolymorphicRootDescriptor <?> ) {
513
516
throw new SemanticException (
514
- "Can't create an UPDATE for a non entity name: " + root .getReferencedPathSource ().getHibernateEntityName ()
517
+ String .format (
518
+ "Target type '%s' in update statement is not an entity" ,
519
+ root .getReferencedPathSource ().getHibernateEntityName ()
520
+ )
515
521
);
516
522
}
517
523
@@ -779,7 +785,7 @@ else if ( fetchClauseContext == null ) {
779
785
sqmQueryPart .setFetchExpression ( visitLimitClause ( limitClauseContext ) );
780
786
}
781
787
else {
782
- throw new SemanticException ("Can't use both, limit and fetch clause! " );
788
+ throw new SemanticException ("Can't use both limit and fetch clause" );
783
789
}
784
790
}
785
791
}
@@ -961,7 +967,7 @@ public SqmDynamicInstantiation<?> visitInstantiation(HqlParser.InstantiationCont
961
967
);
962
968
}
963
969
catch (ClassLoadingException e ) {
964
- throw new SemanticException ( "Unable to resolve class named for dynamic instantiation : " + className );
970
+ throw new SemanticException ( "Could not resolve class '" + className + "' named for instantiation" );
965
971
}
966
972
}
967
973
else {
@@ -1362,7 +1368,7 @@ public EntityDomainType<?> visitEntityName(HqlParser.EntityNameContext parserEnt
1362
1368
.getJpaMetamodel ()
1363
1369
.getHqlEntityReference ( entityName );
1364
1370
if ( entityReference == null ) {
1365
- throw new UnknownEntityException ( "Could not resolve entity name [ " + entityName + "] as DML target " , entityName );
1371
+ throw new UnknownEntityException ( "Could not resolve target entity ' " + entityName + "' " , entityName );
1366
1372
}
1367
1373
checkFQNEntityNameJpaComplianceViolationIfNeeded ( entityName , entityReference );
1368
1374
if ( entityReference instanceof SqmPolymorphicRootDescriptor <?> && getCreationOptions ().useStrictJpaCompliance () ) {
@@ -1476,7 +1482,7 @@ public SqmRoot<?> visitRootEntity(HqlParser.RootEntityContext ctx) {
1476
1482
}
1477
1483
throw new SemanticException ( "Could not resolve entity or correlation path '" + name + "'" );
1478
1484
}
1479
- throw new SemanticException ( "Could not resolve entity '" + name + "'" );
1485
+ throw new UnknownEntityException ( "Could not resolve root entity '" + name + "'" , name );
1480
1486
}
1481
1487
checkFQNEntityNameJpaComplianceViolationIfNeeded ( name , entityDescriptor );
1482
1488
@@ -1491,7 +1497,7 @@ public SqmRoot<?> visitRootEntity(HqlParser.RootEntityContext ctx) {
1491
1497
1492
1498
if ( processingStateStack .depth () > 1 ) {
1493
1499
throw new SemanticException (
1494
- "Illegal implicit-polymorphic domain path in sub-query : " + entityDescriptor .getName ()
1500
+ "Illegal implicit-polymorphic domain path in subquery ' " + entityDescriptor .getName () + "'"
1495
1501
);
1496
1502
}
1497
1503
}
@@ -2140,7 +2146,7 @@ public SqmPath<?> visitEntityIdReference(HqlParser.EntityIdReferenceContext ctx)
2140
2146
throw new NotYetImplementedFor6Exception ( "Path continuation from `id()` reference not yet implemented" );
2141
2147
}
2142
2148
2143
- throw new SemanticException ( "Path does not reference an identifiable- type : " + sqmPath .getNavigablePath ().getFullPath () );
2149
+ throw new SemanticException ( "Path does not resolve to an entity type ' " + sqmPath .getNavigablePath ().getFullPath () + "'" );
2144
2150
}
2145
2151
2146
2152
@ Override
@@ -2159,15 +2165,17 @@ public SqmPath<?> visitEntityVersionReference(HqlParser.EntityVersionReferenceCo
2159
2165
final SingularPersistentAttribute <Object , ?> versionAttribute = identifiableType .findVersionAttribute ();
2160
2166
if ( versionAttribute == null ) {
2161
2167
throw new SemanticException (
2162
- "`" + sqmPath .getNavigablePath ().getFullPath () + "` resolved to an identifiable-type (`" +
2163
- identifiableType .getTypeName () + "`) which does not define a version"
2168
+ String .format (
2169
+ "Path '%s' resolved to entity type '%s' which does not define a version" ,
2170
+ sqmPath .getNavigablePath ().getFullPath (), identifiableType .getTypeName ()
2171
+ )
2164
2172
);
2165
2173
}
2166
2174
2167
2175
return sqmPath .get ( versionAttribute );
2168
2176
}
2169
2177
2170
- throw new SemanticException ( "Path does not reference an identifiable- type : " + sqmPath .getNavigablePath ().getFullPath () );
2178
+ throw new SemanticException ( "Path does not resolve to an entity type ' " + sqmPath .getNavigablePath ().getFullPath () + "'" );
2171
2179
}
2172
2180
2173
2181
@ Override
@@ -2186,14 +2194,18 @@ public SqmPath<?> visitEntityNaturalIdReference(HqlParser.EntityNaturalIdReferen
2186
2194
final List <? extends PersistentAttribute <Object , ?>> attributes = identifiableType .findNaturalIdAttributes ();
2187
2195
if ( attributes == null ) {
2188
2196
throw new SemanticException (
2189
- "`" + sqmPath .getNavigablePath ().getFullPath () + "` resolved to an identifiable-type (`" +
2190
- identifiableType .getTypeName () + "`) which does not define a natural id"
2197
+ String .format (
2198
+ "Path '%s' resolved to entity type '%s' which does not define a natural id" ,
2199
+ sqmPath .getNavigablePath ().getFullPath (), identifiableType .getTypeName ()
2200
+ )
2191
2201
);
2192
2202
}
2193
2203
else if ( attributes .size () >1 ) {
2194
2204
throw new SemanticException (
2195
- "`" + sqmPath .getNavigablePath ().getFullPath () + "` resolved to an identifiable-type (`" +
2196
- identifiableType .getTypeName () + "`) which defines multiple natural ids"
2205
+ String .format (
2206
+ "Path '%s' resolved to entity type '%s' which defines multiple natural ids" ,
2207
+ sqmPath .getNavigablePath ().getFullPath (), identifiableType .getTypeName ()
2208
+ )
2197
2209
);
2198
2210
}
2199
2211
@@ -2203,7 +2215,7 @@ else if ( attributes.size() >1 ) {
2203
2215
return sqmPath .get ( naturalIdAttribute );
2204
2216
}
2205
2217
2206
- throw new SemanticException ( "Path does not reference an identifiable- type : " + sqmPath .getNavigablePath ().getFullPath () );
2218
+ throw new SemanticException ( "Path does not resolve to an entity type ' " + sqmPath .getNavigablePath ().getFullPath () + "'" );
2207
2219
}
2208
2220
2209
2221
@ Override
@@ -3501,7 +3513,7 @@ public Object visitExtractFunction(HqlParser.ExtractFunctionContext ctx) {
3501
3513
public Object visitFormat (HqlParser .FormatContext ctx ) {
3502
3514
String format = QuotingHelper .unquoteStringLiteral ( ctx .getChild ( 0 ).getText () );
3503
3515
if (!FORMAT .matcher (format ).matches ()) {
3504
- throw new SemanticException ("illegal format pattern: '" + format + "'" );
3516
+ throw new SemanticException ("illegal format pattern '" + format + "'" );
3505
3517
}
3506
3518
return new SqmFormat (
3507
3519
format ,
@@ -3681,7 +3693,7 @@ private <X> SqmSubQuery<X> createCollectionReferenceSubQuery(
3681
3693
3682
3694
if ( !(referencedPathSource instanceof PluralPersistentAttribute ) ) {
3683
3695
throw new PathException (
3684
- "Illegal attempt to treat non-plural path as a plural path : " + pluralAttributePath .getNavigablePath ()
3696
+ "Path is not a plural path ' " + pluralAttributePath .getNavigablePath () + "'"
3685
3697
);
3686
3698
}
3687
3699
final SqmSubQuery <?> subQuery = new SqmSubQuery <>(
@@ -3809,7 +3821,7 @@ public SqmLiteral<Character> visitPadCharacter(HqlParser.PadCharacterContext ctx
3809
3821
final String padCharText = ctx .STRING_LITERAL ().getText ();
3810
3822
3811
3823
if ( padCharText .length () != 3 ) {
3812
- throw new SemanticException ( "Pad character for pad() function must be single character, found: " + padCharText );
3824
+ throw new SemanticException ( "Pad character for pad() function must be single character, found ' " + padCharText + "'" );
3813
3825
}
3814
3826
3815
3827
return new SqmLiteral <>(
@@ -3878,7 +3890,7 @@ public SqmLiteral<Character> visitTrimCharacter(HqlParser.TrimCharacterContext c
3878
3890
: " " ; // JPA says space is the default
3879
3891
3880
3892
if ( trimCharText .length () != 1 ) {
3881
- throw new SemanticException ( "Trim character for trim() function must be single character, found: " + trimCharText );
3893
+ throw new SemanticException ( "Trim character for trim() function must be single character, found ' " + trimCharText + "'" );
3882
3894
}
3883
3895
3884
3896
return new SqmLiteral <>(
@@ -4181,10 +4193,15 @@ protected void reset() {
4181
4193
public SqmPath <?> visitCollectionElementNavigablePath (HqlParser .CollectionElementNavigablePathContext ctx ) {
4182
4194
final SqmPath <?> pluralAttributePath = consumeDomainPath ( (HqlParser .PathContext ) ctx .getChild ( 2 ) );
4183
4195
final SqmPathSource <?> referencedPathSource = pluralAttributePath .getReferencedPathSource ();
4196
+ final TerminalNode firstNode = (TerminalNode ) ctx .getChild ( 0 );
4184
4197
4185
4198
if ( !(referencedPathSource instanceof PluralPersistentAttribute <?, ?, ?> ) ) {
4186
4199
throw new PathException (
4187
- "Illegal attempt to treat non-plural path as a plural path : " + pluralAttributePath .getNavigablePath ()
4200
+ String .format (
4201
+ "Argument of '%s' is not a plural path '%s'" ,
4202
+ firstNode .getSymbol ().getText (),
4203
+ pluralAttributePath .getNavigablePath ()
4204
+ )
4188
4205
);
4189
4206
}
4190
4207
@@ -4194,7 +4211,6 @@ public SqmPath<?> visitCollectionElementNavigablePath(HqlParser.CollectionElemen
4194
4211
if ( attribute .getCollectionClassification () != CollectionClassification .MAP ) {
4195
4212
throw new StrictJpaComplianceViolation ( StrictJpaComplianceViolation .Type .VALUE_FUNCTION_ON_NON_MAP );
4196
4213
}
4197
- final TerminalNode firstNode = (TerminalNode ) ctx .getChild ( 0 );
4198
4214
if ( firstNode .getSymbol ().getType () == HqlParser .ELEMENTS ) {
4199
4215
throw new StrictJpaComplianceViolation ( StrictJpaComplianceViolation .Type .HQL_COLLECTION_FUNCTION );
4200
4216
}
@@ -4219,8 +4235,13 @@ public SqmPath<?> visitCollectionIndexNavigablePath(HqlParser.CollectionIndexNav
4219
4235
final SqmPathSource <?> referencedPathSource = pluralAttributePath .getReferencedPathSource ();
4220
4236
4221
4237
if ( !(referencedPathSource instanceof PluralPersistentAttribute <?, ?, ?> ) ) {
4238
+ final TerminalNode firstNode = (TerminalNode ) ctx .getChild ( 0 );
4222
4239
throw new PathException (
4223
- "Illegal attempt to treat non-plural path as a plural path : " + pluralAttributePath .getNavigablePath ()
4240
+ String .format (
4241
+ "Argument of '%s' is not a plural path '%s'" ,
4242
+ firstNode .getSymbol ().getText (),
4243
+ pluralAttributePath .getNavigablePath ()
4244
+ )
4224
4245
);
4225
4246
}
4226
4247
0 commit comments