• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: ERXValidationException out of a Unique Constraint Violation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ERXValidationException out of a Unique Constraint Violation


  • Subject: Re: ERXValidationException out of a Unique Constraint Violation
  • From: Chuck Hill <email@hidden>
  • Date: Tue, 27 May 2008 10:08:39 -0700

Hi Paul,


On May 27, 2008, at 2:45 AM, Paul Stringer wrote:

Hi,

I'm following the PracticalWebObjects advice to handle unique values validation at the database and then handle it in thrown EOGeneralAdaptorExceptions. Wish I'd checked this before I wasted time pre-checking for all this in validateKey() which was my first approach, follow the advice don't do it! :)

Ah, the voice of experience. :-)


First thing I found when implementing this was you don't get a nice EOAdaptorFailureKey on a unique constraint so I'm having to check the error for a 'Integrity constraint violation' string but so far so good. What I wanted then was a nice ERXValidationException with the Value and KeyPath to be able to display something meaningful to the user.

You are not really going to get that. This exception comes from the database and the database knows nothing of entities and properties. The best you can hope for is a table name to match up to a Entity.


I don't use Wonder's validation, but with ours I can define messages like:

User.uniqueLoginName.integrityConstraintViolation = "There is already a user with that login name.";

where "uniqueLoginName" is the constraint name in the database.



After looking at it, my solution was to check the SQLException out of the Failed EOAdaptorOperation (copying bits from ERXAdaptorUtilities.isOptimisticLockingFailure()) and regex the SQLException .getMessage() for the values. Seemed kinda hacky but maybe because I'm comparing to clean regular EOValidation.

I use the SQL error codes to determine what kind of failure it was, and then regex to get the table name and constraint name. Use ERXEOAccessUtilities.entityUsingTable(ec, tableName) to try an map the table name to an Entity (can't be exact for single table inheritance).



Any better ways to approach this or am I basically on the right track. The only thing I see as a potential problem is that the errors that come back maybe database specific and so therefore the code is not db independant. I'm using FrontBase right now if it makes any difference.


DB dependent stuff usually goes in ERXSQLHelper sub-classes. I thought Mike did some work in this area recently, but I don't see it.

Chuck

--

Practical WebObjects - for developers who want to increase their overall knowledge of WebObjects or who are trying to solve specific problems.
http://www.global-village.net/products/practical_webobjects






_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: ERXValidationException out of a Unique Constraint Violation
      • From: Mike Schrag <email@hidden>
References: 
 >ERXValidationException out of a Unique Constraint Violation (From: Paul Stringer <email@hidden>)

  • Prev by Date: Re: Stupid Relationship question.
  • Next by Date: Re: ERXValidationException out of a Unique Constraint Violation
  • Previous by thread: ERXValidationException out of a Unique Constraint Violation
  • Next by thread: Re: ERXValidationException out of a Unique Constraint Violation
  • Index(es):
    • Date
    • Thread