# How to shut off an error or warning on a per query basis using Hibernate

**URL:** <https://discourse.hibernate.org/t/how-to-shut-off-an-error-or-warning-on-a-per-query-basis-using-hibernate/1879>\
**Category:** Hibernate ORM\
**Created:** [December 13, 2018, 4:17am UTC](https://discourse.hibernate.org/t/how-to-shut-off-an-error-or-warning-on-a-per-query-basis-using-hibernate/1879 "2018-12-13T04:17:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![barnaby71](https://avatars.discourse-cdn.com/v4/letter/b/ea5d25/32.png) [@barnaby71](https://discourse.hibernate.org/u/barnaby71)\
**Post date:** [December 13, 2018, 4:17am UTC](https://discourse.hibernate.org/t/how-to-shut-off-an-error-or-warning-on-a-per-query-basis-using-hibernate/1879/1 "2018-12-13T04:17:59Z")

</div>

I am performing a query and I’m expecting lock to fail sometimes. I am catching the exception but i do not want the warning and errors bellow going to log. I want to control this per query or session I don’t want to shut the logging off completely.

```auto
04:14:32,107 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 1) SQL Error: 0, SQLState: 55P03
04:14:32,109 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (EJB default - 1) ERROR: could not obtain lock on row in relation ...
04:14:32,110 ERROR [stderr] (EJB default - 1) Exception org.hibernate.PessimisticLockException: could not extract ResultSet
04:14:32,110 ERROR [stderr] (EJB default - 1) Exception message could not extract ResultSet

```

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [December 13, 2018, 8:18am UTC](https://discourse.hibernate.org/t/how-to-shut-off-an-error-or-warning-on-a-per-query-basis-using-hibernate/1879/2 "2018-12-13T08:18:51Z")

</div>

Hibernate, like many other frameworks, does not provide this feature.

The logger can be either activated or disabled. You can disabled it for a single method call. The only way to achieve that is if you parse the log using a tool like Logstash and you filter out the ERROR message that contain a given MDC key. Hibernate uses JBoss Logging which also supports MDC. For more details about MDC, check out [this article](https://www.baeldung.com/mdc-in-log4j-2-logback). Basically, you will have to inject an MDC key in all log entries for a given data access method so that you can ignore all ERROR and WARN messages containing that MDC key.
