Re: UniqueConstraintException and Mysql
Re: UniqueConstraintException and Mysql
- Subject: Re: UniqueConstraintException and Mysql
- From: Theodore Petrosky <email@hidden>
- Date: Tue, 17 Jan 2017 07:28:49 -0500
I have never needed to do anything special to make this work with Postgresql! Postgresql worked fine out of the box. Put the index on the attribute, all the ValidationTemplate.strings.
My question is, do I need to do something special with mysql?
Ted
> On Jan 17, 2017, at 3:28 AM, Fabian Peters <email@hidden> wrote:
>
> 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