Environment: Hibernate 4.2.6
Scenario: hibernate logs “ERROR” for a specific "unique constraint PK_XXX violated" sql exception. However due to our specific multiple instance deployment scenario, we need to tweak this to “INFO” level for this specific "unique constraint PK_XXX violated" sql exception. (So it does not confuse IT folks).
In other words, technically it is "ERROR", but it is "INFO" from business perspective.
Currently:
2016.01.19 13.20.14,299 [ ERROR ][ ][ ][ ] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - logExceptions() ORA-00001: unique constraint (PK_LOCKINFO) violated
Desired:
2016.01.19 13.20.14,299 [ INFO ][ ][ ][ ] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - logExceptions() ORA-00001: unique constraint (PK_LOCKINFO) violated
What is the easiest way to go forward? Options I could think of:
- Modify hibernate internal class "org.hibernate.engine.jdbc.spi.SqlExceptionHelper" , then recompile the “hibernate” jar
The specific customization is: in case of "unique constraint PK_LOCKINFO violated" sql exception, log it as "INFO" level instead of "ERROR" level. But any other sql exceptions should still be logged as "ERROR" level. This option poses a challenge as we go forward. We will have to do it every time hibernate upgrades.
have a class to extend & customize hibernate class "org.hibernate.engine.jdbc.spi.SqlExceptionHelper" in our own codebase This way we do not have to compile a “hibernate” jar. Is this possible?
Add a after-the-fact-listener in our code which scans through "log" constantly, then do something about it
Not sure if I like option #3 or not. Seems too awkward.
Any other options?