diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/DatabaseException.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/DatabaseException.java index c271f71ffb3..16a7fe7686e 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/DatabaseException.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/exceptions/DatabaseException.java @@ -22,6 +22,7 @@ import org.eclipse.persistence.internal.sessions.AbstractSession; import org.eclipse.persistence.exceptions.i18n.ExceptionMessageGenerator; import org.eclipse.persistence.sessions.DataRecord; +import org.eclipse.persistence.logging.SessionLog; /** *
Purpose: @@ -210,7 +211,7 @@ public String getMessage() { } else { writer.write("000"); } - if (getCall() != null) { + if (getCall() != null && session.shouldLog(SessionLog.FINE, SessionLog.SQL)) { writer.write(cr()); writer.write(getIndentationString()); writer.write(ExceptionMessageGenerator.getHeader("CallHeader")); diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java index 5a22647d3d7..586c6ce238e 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/sessions/AbstractSession.java @@ -1856,6 +1856,10 @@ public Object executeQuery(DatabaseQuery query, AbstractRecord row, int retryCou if (queryException.getSession() == null) { queryException.setSession(this); } + if (queryException.getQuery().getSession() == null) { + queryException.getQuery().setSession(this); + } + queryException.getQuery().setOccurException(true); } else if (exception instanceof DatabaseException) { DatabaseException databaseException = (DatabaseException)exception; if (databaseException.getQuery() == null) { @@ -1867,6 +1871,10 @@ public Object executeQuery(DatabaseQuery query, AbstractRecord row, int retryCou if (databaseException.getSession() == null) { databaseException.setSession(this); } + if (databaseException.getQuery().getSession() == null) { + databaseException.getQuery().setSession(this); + } + databaseException.getQuery().setOccurException(true); //if this query is a read query outside of a transaction then we may be able to retry the query if (!isInTransaction() && query.isReadQuery() && getDatasourceLogin() instanceof DatabaseLogin) { final int count = getLogin().getQueryRetryAttemptCount(); diff --git a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/DatabaseQuery.java b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/DatabaseQuery.java index 1d21601adee..b553b9e3454 100644 --- a/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/DatabaseQuery.java +++ b/foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/queries/DatabaseQuery.java @@ -60,6 +60,7 @@ import org.eclipse.persistence.sessions.remote.*; import org.eclipse.persistence.sessions.DatabaseRecord; import org.eclipse.persistence.sessions.SessionProfiler; +import org.eclipse.persistence.logging.SessionLog; /** *
@@ -336,6 +337,9 @@ public enum ParameterType {POSITIONAL, NAMED} /** Allow the reserved pound char used to delimit bind parameters to be overridden */ protected String parameterDelimiter; + /** Flag to control the sql log */ + protected boolean occurException = false; + /** * PUBLIC: Initialize the state of the query */ @@ -2670,6 +2674,20 @@ public void storeBypassCache() { setShouldStoreBypassCache(true); } + /** + * Return true if exception has occured. + */ + public boolean isOccurException() { + return occurException; + } + + /** + * Set if exception has occurd. + */ + public void setOccurException(boolean occurException) { + this.occurException = occurException; + } + @Override public String toString() { String referenceClassString = ""; @@ -2681,6 +2699,9 @@ public String toString() { if ((getName() != null) && (!getName().equals(""))) { nameString = "name=\"" + getName() + "\" "; } + if (isOccurException() && !session.shouldLog(SessionLog.FINE, SessionLog.SQL)) { + return getClass().getSimpleName() + "(" + nameString + referenceClassString + ")"; + } if (isSQLCallQuery()) { queryString = "sql=\"" + getSQLString() + "\""; } else if (isJPQLCallQuery()) {