Re: UniqueConstraintException and Mysql

2017-01-17 Thread Fabian Peters
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 :
> 
> 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: 
>  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:"t...@tp.com"(email)>: Next exception:SQL State:23000 -- error code: 1062 
> -- msg: Duplicate entry 't...@tp.com' for key ‘login_idx'
> 
> there it is:
> error code: 1062 -- msg: Duplicate entry 't...@tp.com' 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  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/lists.fabian%40e-lumo.com
> 
> This email sent to lists.fab...@e-lumo.com


 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

UniqueConstraintException and Mysql

2017-01-16 Thread Theodore Petrosky
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: 
: Next exception:SQL State:23000 -- error code: 1062 -- 
msg: Duplicate entry 't...@tp.com' for key ‘login_idx'

there it is:
error code: 1062 -- msg: Duplicate entry 't...@tp.com' 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  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com