Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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


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.

0 votes



5 answers

Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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)

0 votes


Permanent link
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

0 votes


Permanent link
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

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Jan 15 '10, 10:18 p.m.

Question was seen: 8,294 times

Last updated: Jan 15 '10, 10:18 p.m.

Confirmation Cancel Confirm