Duplicate key value while saving a Jazz component
Hello,
I've created a simple ecore model with one class "MyResource" for a Jazz component but when I save it using the code snippet below I get this SQL error: SQL: INSERT INTO MY_RESOURCE.MY_RESOURCE (STATE_ID, ITEM_ID, CONTEXT_ID, MODIFIED, MODIFIED_BY_ITEM_ID, ID, NAME, CONTENT_INTERNAL_ID, CONTENT_CONTENT_LENGTH, CONTENT_CONTENT_TYPE, CONTENT_CHECKSUM, CREATION_DATE, CREATOR_ITEM_ID, PROJECT_AREA_ITEM_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) SQL Exception #1 SQL Message: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'MY_RESOURCE_ID_DX' defined on 'MY_RESOURCE'. SQL State: 23505 Error Code: 20000
Which primary key it is referring too? Each object seem to have their own UUID. Thanks for your help. |
5 answers
Jared Burns (4.5k●2●9)
| answered Jan 18 '10, 8:52 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
On Sat, 16 Jan 2010 03:22:55 +0000, marly wrote:
MyResource myResource = (MyResource) You don't need to set the item id when you create an item. It will be automatically created by the platform. You should delete the line that reads "myResource.setItemId(UUID.generate());" -- Jared Burns Jazz Process Team |
That didn't fix it.
I'm wondering does a resource saved to a Jazz repository need to be within the scope of a Project Area? In my case it isn't maybe that's why I'm having this duplicate error because I was able to save one resource only, after that I'm getting the duplicate error... Thanks |
I tried saving the resource within the scope of a Project area but I still get the error with the duplicate key:
Here is the error I'm getting. I'll appreciate any pointers as I don't understand what is happening.
|
I tried saving the resource within the scope of a Project area but I It looks like you have an 'ID' field defined in your model, but you don't set it in in your code, so it will always be '-1'. The ID very likely has a uniqueness constraint, so no two items with the same ID can be saved. You must either set the ID to a new value for each item, or remove it from the model if you don't need it. -- Regards, Patrick Jazz Work Item Team |
Perfect, that fixed it. Thanks a lot for your help.
I tried saving the resource within the scope of a Project area but I It looks like you have an 'ID' field defined in your model, but you don't set it in in your code, so it will always be '-1'. The ID very likely has a uniqueness constraint, so no two items with the same ID can be saved. You must either set the ID to a new value for each item, or remove it from the model if you don't need it. -- Regards, Patrick Jazz Work Item Team |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.