• 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: UniqueConstraintException and Mysql
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UniqueConstraintException and Mysql


  • Subject: Re: UniqueConstraintException and Mysql
  • From: Fabian Peters <email@hidden>
  • Date: Tue, 17 Jan 2017 09:28:56 +0100

Hi Ted,

No idea about MySQL, but for Postgres you need to subclass the PostgresqlSQLHelper and implement something like:


    public boolean handleDatabaseException(EODatabaseContext databaseContext,
                                           Throwable throwable) {
        boolean handleDatabaseException = false;
        if (throwable != null && throwable.getMessage() != null) {
            if (throwable.getMessage().contains(
                    "unique_something")) {
		handleDatabaseException = true;
		databaseContext.rollbackChanges();
		throw ERXValidationFactory.defaultFactory() .createCustomException(null, SomeEO.ATTRIBUTE_name, null, "DuplicateNameConstraintException");
	    }
        }
        return handleDatabaseException;
    }

HTH, Fabian

> Am 17.01.2017 um 05:15 schrieb Theodore Petrosky <email@hidden>:
>
> I have this working fine with my postgresql backend. I created an index on the User entity. I have a Constraint Distinct on the login attribute. The index is named login_idx.
>
> so in my ValidationTemplate.strings file I have:
>
> {
> 	"UniqueConstraintException.login_idx" = "Please choose a different login (It must be unique).";
>
> }
>
> This doesn’t seem to work with a MySQL backend or I am not remembering to wire something else in. After I ran the migrations, I see the index on the table and I see the errors in my console:
>
> EvaluateExpression failed: <com.webobjects.jdbcadaptor._MySQLPlugIn$MySQLExpression: "INSERT INTO User(unreadcount, website, title, phone, active, story, created, keywords, ipaddress, adjusted, status, lastlogin, kind, id, role, language, timezone, type, password, email) VALUES (NULL, NULL, ?, NULL, ?, NULL, ?, NULL, NULL, ?, NULL, NULL, NULL, ?, NULL, NULL, NULL, NULL, ?, ?)" withBindings: 1:"User"(title), 2:true(active), 3:2017-01-17 04:09:40(created), 4:2017-01-17 04:09:40(adjusted), 5:7(id), 6:"SlCWtgVlm5W/+zMGkl9pKcA1MMg="(password), 7:"email@hidden"(email)>: Next exception:SQL State:23000 -- error code: 1062 -- msg: Duplicate entry 'email@hidden' for key ‘login_idx'
>
> there it is:
> error code: 1062 -- msg: Duplicate entry 'email@hidden' for key ‘login_idx'
>
> so Mysql is complaining and i am not catching it correctly. Googling doesn’t seem to help here.
>
> Ted
> _______________________________________________
> 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


 _______________________________________________
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: UniqueConstraintException and Mysql
      • From: Theodore Petrosky <email@hidden>
References: 
 >UniqueConstraintException and Mysql (From: Theodore Petrosky <email@hidden>)

  • Prev by Date: UniqueConstraintException and Mysql
  • Next by Date: Re: UniqueConstraintException and Mysql
  • Previous by thread: UniqueConstraintException and Mysql
  • Next by thread: Re: UniqueConstraintException and Mysql
  • Index(es):
    • Date
    • Thread