JBoss EAP 6.4 with Hibernate - 在日志文件中隐藏特定的 Oracle 异常

JBoss EAP 6.4 with Hibernate - Hide a specific Oracle exception in log file

使用 PersistenceException -> SQLException -> getErrorCode(),我在我的日志中隐藏了一个特定的 Oracle 错误。问题是,在我的 server.log 中,我仍然发现像这样的行:

WARN  25 Sep 2018 12:14:47,121 - id  - org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ms 5829302 SQL Error: 13333, SQLState: 72000
ERROR 25 Sep 2018 12:14:47,121 - id  - org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ms 5829302 ORA-13333: invalid LRS measure
ORA-06512: at "MDSYS.SDO_LRS", line 3149
ORA-06512: at line 1

这不是我专门记录的。

这是我的代码:

try {
 try {
  //business stuff
 } catch (PersistenceException persEx) {
  if (persEx.getCause() != null && persEx.getCause() instanceof GenericJDBCException) {
   GenericJDBCException jdbcEx = (GenericJDBCException) persEx.getCause();
   SQLException sqlEx = (SQLException) jdbcEx.getCause();
   if (sqlEx.getErrorCode() == 13333) {
    //handling ORA-13333: invalid LRS measure as an info
    log.info("Possible invalid LRS measure");
   } else {
    throw persEx; // do not swallow unhandled exceptions
   }
  } else {
   throw persEx; // do not swallow unhandled exceptions
  }
 } catch (Exception e) {
  log.error("Other exception:" + e.getMessage());
 }
} catch (Exception e) {
 log.error("Exception to log:" + e.getMessage());
}

通过向 JBoss 日志处理程序添加特定过滤器解决,在本例中为

<filter-spec value="all(not(match(&quot;ORA-13333&quot;)), not(match(&quot;SQL Error: 13333&quot;)))"/>

希望对其他人有用。