Announcement Announcement Module
Collapse
No announcement yet.
Unique Constraint - How to validate against? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unique Constraint - How to validate against?

    I have a database table that implements a unique contraint. When I add a new record to this via. jsp (Spring MVC) I am presented with a rather nasty looking stack trace which informs me that I have violated the unique constraint. Is there a way to capture these and present this page in a user friendly manner - possibly via. the validator. Better still is there a way to present the form again along with error messages as I have done for other validation errors?

    I realise I could wire my service class into the validator and run a db query through this but I am loathed to do that - it seems to me that the service class should only be accessed from the controller (that's just a hunch - I'm not well schooled in the art of OO).

  • #2
    There's nothing wrong from wiring dependencies into the validator.

    Also, you might consider catching the exception from the DAO and wrapping it in a business exception. That way, you have something explicit to look for. You can then have your service layer throw the exception, and your web tier can catch it and generate the appropriate error message, and call showForm() to redisplay the form.

    Comment

    Working...
    X