New Posts New Posts RSS Feed: DuplicateKey Error
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

DuplicateKey Error

 Post Reply Post Reply
Author
aladdin View Drop Down
Newbie
Newbie
Avatar

Joined: 18-Dec-2007
Posts: 11
Post Options Post Options   Quote aladdin Quote  Post ReplyReply Direct Link To This Post Topic: DuplicateKey Error
    Posted: 18-Dec-2007 at 2:15pm
When create new entity(on added before save)  the PersistenceManager use the PooledNumericIdGenerator class, to create primary key  to non AutoIncrement field and post it -1.Now, after save if created duplicated key how can the Verification engine to catch the error unfortunately used AdoHelper methods.

Thanks for all.
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 19-Dec-2007 at 4:20pm
If you were to use the Verification engine to try to catch this error you would have to write your own custom verifier. In this case that would be quite complicated. That is probably not the right way to accomplish what you want to do.

If you are using the PooledNumericIdGenerator then in your NextId table you have to have an entry for the name of the table that you are doing Id generation for. If you have that then you should not get a duplicate key error.

Hope this helps.

Paul Karsh
IdeaBlade Support
Back to Top
aladdin View Drop Down
Newbie
Newbie
Avatar

Joined: 18-Dec-2007
Posts: 11
Post Options Post Options   Quote aladdin Quote  Post ReplyReply Direct Link To This Post Posted: 29-Jan-2008 at 9:29am
Dear Paul,

about your second opinion, if deleted the last record of Invoices then NextId table loose the serial number, and

the user must be have permission to modify the NextId table. Now, if the user is stupid maybe save wrong id in

the NextId table. In this case we get a duplicate key error.How can to protect ?

Thanks
Back to Top
pkarsh View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Location: United States
Posts: 32
Post Options Post Options   Quote pkarsh Quote  Post ReplyReply Direct Link To This Post Posted: 29-Jan-2008 at 10:39am
I'm afraid I don't understand your question. How would deleting the last record of a table cause you to lose the value entered in the NextId table? Are you trying to re-use primary keys of deleted records? We recommend against that. Under ordinary circumstances the Id generator and not end-users should be writing into the NextId table. If for some reason you cannot adhere to this rule, then I suppose you could put your SaveChanges call into a try-catch loop (which is a good idea anyway) and do something to handle a Save failure due to a Duplicate key error. If your primary keys are in ascending order, meaning, for example, that you would not assign a primary key of 3 after having assigned one of 4, then you might consider running a query to get the MAX value of the primary key column.

If you wish to send me a private email to explain your situation in more detail then click on the link to my user name and you will see a button that will enable you to do so.

Paul Karsh
IdeaBlade Support
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down