improve Jakarta Data exception messages

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-11 19:31:07 +02:00
parent 23dc51d291
commit 04d22686bb
3 changed files with 9 additions and 5 deletions

View File

@ -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");
}
}

View File

@ -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)

View File

@ -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");
}