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.
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
On Sat, 16 Jan 2010 03:22:55 +0000, marly wrote:
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
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
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.
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)
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
Perfect, that fixed it. Thanks a lot for your help.
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
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