From 0007f6a8a0ec9d6ade2ce0eeccc8265141c1e18e Mon Sep 17 00:00:00 2001 From: Gavin King Date: Thu, 11 Apr 2024 19:31:07 +0200 Subject: [PATCH] improve Jakarta Data exception messages Signed-off-by: Gavin King --- .../hibernate/processor/annotation/AbstractQueryMethod.java | 6 +++--- .../org/hibernate/processor/annotation/IdFinderMethod.java | 6 +++++- .../org/hibernate/processor/annotation/LifecycleMethod.java | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java index 5b380dd43c..12ec1628c2 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AbstractQueryMethod.java @@ -279,14 +279,14 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod { .append(" exception) {\n") .append("\t\tthrow new ") .append(annotationMetaEntity.importType("jakarta.data.exceptions.EmptyResultException")) - .append("(exception);\n") + .append("(exception.getMessage(), exception);\n") .append("\t}\n") .append("\tcatch (") .append(annotationMetaEntity.importType("jakarta.persistence.NonUniqueResultException")) .append(" exception) {\n") .append("\t\tthrow new ") .append(annotationMetaEntity.importType("jakarta.data.exceptions.NonUniqueResultException")) - .append("(exception);\n") + .append("(exception.getMessage(), exception);\n") .append("\t}\n"); } declaration @@ -295,7 +295,7 @@ public abstract class AbstractQueryMethod extends AbstractAnnotatedMethod { .append(" exception) {\n") .append("\t\tthrow new ") .append(annotationMetaEntity.importType("jakarta.data.exceptions.DataException")) - .append("(exception);\n") + .append("(exception.getMessage(), exception);\n") .append("\t}\n"); } } diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/IdFinderMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/IdFinderMethod.java index e192d35f58..d926c1ae1a 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/IdFinderMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/IdFinderMethod.java @@ -86,7 +86,11 @@ public class IdFinderMethod extends AbstractFinderMethod { declaration .append("\t\tif (_result == null) throw new ") .append(annotationMetaEntity.importType("jakarta.data.exceptions.EmptyResultException")) - .append("(new ") + .append("(\"No '") + .append(annotationMetaEntity.importType(entity)) + .append("' for given id [\" + ") + .append(paramName) + .append(" + \"]\",\n\t\t\t\tnew ") .append(annotationMetaEntity.importType("org.hibernate.ObjectNotFoundException")) .append("((Object) ") .append(paramName) diff --git a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/LifecycleMethod.java b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/LifecycleMethod.java index ba9fd0e073..8ed0db96d2 100644 --- a/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/LifecycleMethod.java +++ b/tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/LifecycleMethod.java @@ -192,7 +192,7 @@ public class LifecycleMethod extends AbstractAnnotatedMethod { .append(" exception) {\n") .append("\t\tthrow new ") .append(annotationMetaEntity.importType(convertedException)) - .append("(exception);\n") + .append("(exception.getMessage(), exception);\n") .append("\t}\n"); }