Add a unique constraint to the database. That is the only way this will work. Your code below could return EOObjectNotAvailableException and then another instance inserts the row before your insert. The database is your friend here. With the unique constraint
you don't need to fetch first, just do the insert and see if it throws.

Alan


On Feb 20, 2009, at 10:40 AM, Gustavo Pizano wrote:

Hello all.
Well I want to insert a EObject into the database, I found that the objectMatchingKeyAndValue will return me the object with the given parameters, and if not found will throw and EOObjectNotAvailableException. Now, I need to insert the new objects, but I need to be sure that they don't exist in the database, the entity has a attribute called code, which is not the primary key, so I was thinking in using the following.

try{
Product p = (Product )EOUtilities .objectMatchingKeyAndValue (editingContext(),"Product",Product.CODE_KEY, code);
}catch (EOObjectNotAvailableException e){
        

 //insert the new object into the EC, and save it

}

the problem i see, is that if the object in fact exists, I must alert the user that this particular product exist already, so Im feeling doing the things in the wrong way, I was thinking in putting a throw exception before the catch and with that alert the user... but i dunno i feel kinda weird doing this...



Suggestions??


Thanks

Gus




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/award %40apple.com

This email sent to [email protected]

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

This email sent to [email protected]

Reply via email to