Skip to content

Commit 9244330

Browse files
author
Radek Felcman
authored
JPQL NEW operator check for unsupported types (#2468)
Fixes #2432 Signed-off-by: Radek Felcman <radek.felcman@oracle.com>
1 parent 0741c00 commit 9244330

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/QueryException.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -169,6 +169,7 @@ public class QueryException extends ValidationException {
169169
public final static int UPDATE_ALL_QUERY_ADD_UPDATE_DEFINES_WRONG_FIELD = 6135;
170170
public final static int POLYMORPHIC_REPORT_ITEM_NOT_SUPPORTED = 6136;
171171
public final static int EXCEPTION_WHILE_USING_CONSTRUCTOR_EXPRESSION = 6137;
172+
public final static int EXCEPTION_WHILE_USING_CONSTRUCTOR_EXPRESSION_WRONG_TYPE = 6184;
172173
public final static int TEMP_TABLES_NOT_SUPPORTED = 6138;
173174
public final static int MAPPING_FOR_FIELDRESULT_NOT_FOUND = 6139;
174175
public final static int JOIN_EXPRESSIONS_NOT_APPLICABLE_ON_NON_OBJECT_REPORT_ITEM = 6140;
@@ -541,6 +542,18 @@ public static QueryException exceptionWhileUsingConstructorExpression(Exception
541542
return queryException;
542543
}
543544

545+
/**
546+
* An exception was throwing while using a ReportQuery with a constructor expression and wrong type is passed to the constructor.
547+
*/
548+
public static QueryException exceptionWhileUsingConstructorWrongTypeExpression(Class<?> argumentType, DatabaseQuery query) {
549+
Object[] args = { argumentType.getName() };
550+
551+
QueryException queryException = new QueryException(ExceptionMessageGenerator.buildMessage(QueryException.class, EXCEPTION_WHILE_USING_CONSTRUCTOR_EXPRESSION_WRONG_TYPE, args));
552+
queryException.setErrorCode(EXCEPTION_WHILE_USING_CONSTRUCTOR_EXPRESSION_WRONG_TYPE);
553+
queryException.setQuery(query);
554+
return queryException;
555+
}
556+
544557
/**
545558
* PUBLIC:
546559
* Return the exception error message.

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/i18n/QueryExceptionResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 1998, 2023 IBM Corporation and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -214,7 +214,8 @@ public final class QueryExceptionResource extends ListResourceBundle {
214214
{ "6180", "serialized sopObject is not found in [{0}] in [{1}]"},
215215
{ "6181", "sopObject has a wrong version [{0}] in [{1}] in [{2}]"},
216216
{ "6182", "sopObject has a wrong primary key [{0}] in [{1}] in [{2}]"},
217-
{ "6183", "The mapping type {1} for attribute {2} from {0} is not supported with Query By Example functionality. If the attribute can safely be ignored then add it to the ignore list or set example validation to false in the policy."}
217+
{ "6183", "The mapping type {1} for attribute {2} from {0} is not supported with Query By Example functionality. If the attribute can safely be ignored then add it to the ignore list or set example validation to false in the policy."},
218+
{ "6184", "Incorrect value type {0} is passed to the constructor expression. Complex types like arrays, collections, objects are not supported." },
218219

219220
};
220221

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/ConstructorReportItem.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1998, 2025 Oracle and/or its affiliates. All rights reserved.
33
*
44
* This program and the accompanying materials are made available under the
55
* terms of the Eclipse Public License v. 2.0 which is available at
@@ -177,6 +177,9 @@ public void initialize(ReportQuery query) throws QueryException {
177177
constructorArgTypes[index] = (Class) mapping.getContainerPolicy().getKeyType();
178178
}
179179
} else {
180+
if (mapping.isDirectCollectionMapping()) {
181+
throw QueryException.exceptionWhileUsingConstructorWrongTypeExpression(mapping.getContainerPolicy().getContainerClass(), query);
182+
}
180183
constructorArgTypes[index] = mapping.getAttributeClassification();
181184
}
182185
} else if (argumentItem.getResultType() != null) {

0 commit comments

Comments
 (0)