You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/02/11 09:02:13 UTC
[isis] branch ISIS-2502-ex.recog updated: ISIS-2502: Eclipselink
JPA Dialect: be smarter when translating generic ex. (2)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch ISIS-2502-ex.recog
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/ISIS-2502-ex.recog by this push:
new 33bf384 ISIS-2502: Eclipselink JPA Dialect: be smarter when translating generic ex. (2)
33bf384 is described below
commit 33bf3841ee8dc300ba1ccdc99c822ceb8f07afd3
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Feb 11 10:01:58 2021 +0100
ISIS-2502: Eclipselink JPA Dialect: be smarter when translating generic
ex. (2)
TransactionService: also translate ex. originating from flush, just in case
---
.../jpa/eclipselink/IsisModuleJpaEclipselink.java | 36 ++++++++++++++++++++--
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git a/persistence/jpa/eclipselink/src/main/java/org/apache/isis/persistence/jpa/eclipselink/IsisModuleJpaEclipselink.java b/persistence/jpa/eclipselink/src/main/java/org/apache/isis/persistence/jpa/eclipselink/IsisModuleJpaEclipselink.java
index d4c9085..0c33cd6 100644
--- a/persistence/jpa/eclipselink/src/main/java/org/apache/isis/persistence/jpa/eclipselink/IsisModuleJpaEclipselink.java
+++ b/persistence/jpa/eclipselink/src/main/java/org/apache/isis/persistence/jpa/eclipselink/IsisModuleJpaEclipselink.java
@@ -36,12 +36,14 @@ import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
import org.springframework.jdbc.support.SQLExceptionTranslator;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
+import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect;
import org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
import org.apache.isis.core.config.IsisConfiguration;
import org.apache.isis.persistence.jpa.eclipselink.inject.BeanManagerForEntityListeners;
import org.apache.isis.persistence.jpa.integration.IsisModuleJpaIntegration;
@@ -167,11 +169,12 @@ public class IsisModuleJpaEclipselink extends JpaBaseConfiguration {
if(ex instanceof DataAccessException) {
return (DataAccessException)ex; // has already been translated to Spring's hierarchy
}
-
+
// if its eg. a DatabaseException, it might wrap a java.sql.SQLException
if(getJdbcExceptionTranslator() != null
&& ex.getCause() instanceof SQLException) {
+ //converts SQL exceptions to Spring's hierarchy
val translatedEx = getJdbcExceptionTranslator()
.translate(
"JPA operation: " + ex.getMessage(),
@@ -184,8 +187,35 @@ public class IsisModuleJpaEclipselink extends JpaBaseConfiguration {
}
- //converts javax.persistence exceptions to Spring's hierarchy
- return super.translateExceptionIfPossible(ex);
+ // (null-able) converts javax.persistence exceptions to Spring's hierarchy
+ val translatedEx = super.translateExceptionIfPossible(ex);
+
+ if((translatedEx==null
+ // JpaSystemException is just a generic fallback, try to be smarter
+ || JpaSystemException.class.equals(translatedEx.getClass()))
+ && getJdbcExceptionTranslator() != null) {
+
+ val translatedSqlEx = _Exceptions.streamCausalChain(ex)
+ .filter(nextEx->nextEx instanceof SQLException)
+ .map(SQLException.class::cast)
+ //converts SQL exceptions to Spring's hierarchy
+ .map(nextEx->getJdbcExceptionTranslator()
+ .translate(
+ "JPA operation: " + nextEx.getMessage(),
+ extractSqlStringFromException(nextEx),
+ nextEx))
+ .findFirst()
+ .orElse(null);
+
+ if(translatedSqlEx!=null) {
+ return translatedSqlEx;
+ }
+
+ }
+
+ // (null-able)
+ return translatedEx;
+
}
// -- HELPER