It's all about the answers!

Ask a question

Duplicate key value while saving a Jazz component


m sawires (1462268) | asked Jan 15 '10, 10:18 p.m.
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


MyResource myResource = (MyResource) IMyResource.ITEM_TYPE.createItem();
myResource.setContent(content);
myResource.setName(name);
myResource.setCreator(getAuthenticatedContributor());
myResource.setCreationDate(new Timestamp(System.currentTimeMillis()));
myResource.setDescription(partFileName);
myResource.setContextId(IContext.PUBLIC);
myResource.setItemId(UUID.generate());
myResource.setProjectArea(projectAreaHandle);
IRepositoryItemService repositoryItemService = getService(IRepositoryItemService.class);
myResource = repositoryItemService.saveItem(myResource);


Which primary key it is referring too? Each object seem to have their own UUID.
Thanks for your help.

5 answers



permanent link
Jared Burns (4.4k29) | 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)
IMyResource.ITEM_TYPE.createItem();
myResource.setContent(content);
myResource.setName(name);
myResource.setCreator(getAuthenticatedContributor());
myResource.setCreationDate(new
Timestamp(System.currentTimeMillis()));
myResource.setDescription(partFileName);
myResource.setContextId(IContext.PUBLIC);
myResource.setItemId(UUID.generate());
myResource.setProjectArea(projectAreaHandle); IRepositoryItemService
repositoryItemService = getService(IRepositoryItemService.class);
myResource =
repositoryItemService.saveItem(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

permanent link
m sawires (1462268) | answered Jan 18 '10, 4:50 p.m.
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

permanent link
m sawires (1462268) | answered Jan 18 '10, 10:12 p.m.
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.

com.ibm.team.repository.common.InternalRepositoryException: CRJAZ0447I SQL statement execution failed.Integrity constraint violation
SQL: INSERT INTO myRESOURCE.myRESOURCE (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
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
Class: com.ibm.team.repository.service.internal.dataaccess.write2.Row
Item Handle: com.sample.common.MYResource.impl.MYResourceImpl@7d307d30 (stateId: [UUID _sKM2IQSnEd-cbaUCkiOXgg], itemId: [UUID _q1HSgASnEd-cbaUCkiOXgg], origin: <unset>, immutable: true) (contextId: [UUID _kbnuYAQ6Ed-usKbkLIXudA], modified: 2010-01-18 22:06:51.394, workingCopy: <unset>) (mergePredecessor: null, workingCopyPredecessor: <unset>, workingCopyMergePredecessor: <unset>, predecessor: null) (id: -1, name: test.pdf, description: test.pdf, creationDate: 2010-01-18 22:06:44.222)

permanent link
Patrick Streule (4.9k21) | answered Jan 19 '10, 5:08 a.m.
JAZZ DEVELOPER
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.

com.ibm.team.repository.common.InternalRepositoryException:
CRJAZ0447I SQL statement execution failed.Integrity constraint
violation
SQL: INSERT INTO myRESOURCE.myRESOURCE (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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
...
predecessor: null) (id: -1, name: test.pdf,
description: test.pdf, creationDate: 2010-01-18
22:06:44.222)

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

permanent link
m sawires (1462268) | answered Jan 19 '10, 9:06 a.m.
Perfect, that fixed it. Thanks a lot for your help.

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.

com.ibm.team.repository.common.InternalRepositoryException:
CRJAZ0447I SQL statement execution failed.Integrity constraint
violation
SQL: INSERT INTO myRESOURCE.myRESOURCE (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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
...
predecessor: null) (id: -1, name: test.pdf,
description: test.pdf, creationDate: 2010-01-18
22:06:44.222)

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


Register or to post your answer.