Re:SQL is 43 years old – Here’s why we still use it today
by antoaravinth on Tuesday May 02, 2017 @11:49AM
(#14247362)
Just a noob question on jooq. How do you construct error message which you use to send back to user on SQL exceptions. Like in case of duplicate item, you send back "User already exists". How your handling it? I know jooq just sends DataAccessException, now the question is how your converting that exception to a meaningful message which needs to be sent to say UI?
Re:SQL is 43 years old – Here’s why we still use it today
by lukaseder on Thursday May 04, 2017 @12:13PM
(#14265987)
That's a really interesting question, and the best answer is: You have to write this manually. The SQL/JDBC/jOOQ layer can only generate system exceptions, like a constraint violation exception in this case. But there are many different types of constraints, and many different things that a constraint violation can mean. Only you and your service layer can possibly know how to translate such a violation to a meaningful (localised?) user error message.
Having said so, you could hook in an ExecuteListener into jOOQ to handle errors in a single location: https://www.jooq.org/javadoc/latest/org/jooq/ExecuteListener...
An example that uses the Spring Exception translator: https://github.com/jOOQ/jOOQ/blob/master/jOOQ-examples/jOOQ-...
My only complaint (and it's a minor one that would be hard to get around) is the need to run a code generator for jOOQ after every schema change.