Results 1 to 2 of 2

Thread: Unique Constraint - How to validate against?

  1. #1
    Join Date
    Dec 2005
    Posts
    8

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Hawaii, US
    Posts
    225

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •