Results 1 to 5 of 5

Thread: Detecting unique constraint violation in db independent way

  1. #1

    Default Detecting unique constraint violation in db independent way

    How can i solve this problem in a clean and DB independent way? Imagine i have a Vehicle Object which has several properties that should be unique e.g. chasis no, engine no and registration number. How can i detect if any of this constraints is being violated and then being able to present the user with a clear error message that clearly indicates which property(s) violated the constraint?

    I've tried selecting before saving and it worked for first time saves but fell apart when i tried to do updates. Or is it not possible to do this in DB independent way?

  2. #2
    Join Date
    Sep 2004
    Posts
    1,086

    Default

    Creating unique indexes on your tables and then catching org.springframework.dao.DataIntegrityViolationExce ption should work.

  3. #3

    Default

    Quote Originally Posted by dejanp
    Creating unique indexes on your tables and then catching org.springframework.dao.DataIntegrityViolationExce ption should work.
    Ok i'll try that. Thanks

  4. #4
    Join Date
    Jul 2005
    Posts
    6

    Default

    I also the same problem but unlike you I have only one field that is unique. I am wandering what is the common solution for this problem? I see many unanswer topics with this theme.

    Also, sometimes you getting this exception org.hibernate.exception.ConstraintViolationExcepti on instead of the one you mentioned above.

    Also, if you new record, this is the exception org.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs) you would see.

    Anyway, please let me know if you have it working with your problem.

  5. #5

    Default same problem

    Quote Originally Posted by hhoang
    I also the same problem but unlike you I have only one field that is unique. I am wandering what is the common solution for this problem? I see many unanswer topics with this theme.

    Also, sometimes you getting this exception org.hibernate.exception.ConstraintViolationExcepti on instead of the one you mentioned above.

    Also, if you new record, this is the exception org.hibernate.AssertionFailure: null id in entry (don't flush the Session after an exception occurs) you would see.

    Anyway, please let me know if you have it working with your problem.
    I find that for single unique fields it's not that much of problem. I usually catch org.springframework.dao.DataIntegrityViolationExce ption as that only unique field is the only one that can throw it. So in that case i just call showForm() in my catch block to notify the user of the error. I yet have to test the solution suggested above and if it works i'll probably post some feedback

Similar Threads

  1. Replies: 5
    Last Post: Dec 1st, 2005, 08:09 PM
  2. Replies: 1
    Last Post: Oct 4th, 2005, 06:11 PM
  3. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  4. Integer Constraints in RulesSource?
    By steve_smith in forum Swing
    Replies: 13
    Last Post: Nov 3rd, 2004, 03:55 PM
  5. Unique constraint
    By adepue in forum Swing
    Replies: 1
    Last Post: Oct 19th, 2004, 06:23 PM

Posting Permissions

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