cancel
Showing results for 
Search instead for 
Did you mean: 

Mobile 7.1 insert new record issue

anesh_kumar
Active Participant
0 Kudos

Hi

I am trying to insert a new item by selecting the header record

it is ending up with a Illegal state exception Caused by: java.sql.SQLException: Duplicate key: XXXXXX

experts could you please check this thanks !!!!

below is the code i am using to insert the item

ZkumarHeader header = (ZkumarHeader)wdContext.nodezkumar_srv().nodeget_header_asset().nodeget_header_assetOutput().getCurrentElement().model();

ZkumarItem item;

if (header.getItems().size() > 0)

{

item = (ZkumarItem)header.getItems().toArray()[0];

}

else

{

item = header.createNewItems();

}

header.addToItems(item);

wdContext.nodezkumar_srv().nodeget_item_asset().nodeget_item_assetOutput().bind(Collections.singleton(item));

wdContext.nodezkumar_srv().nodeget_item_asset().nodeget_item_assetOutput().setLeadSelection(0);

OcaRoot.getInstance().commit();

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi Anesht,

I think the problem is in the if else block

if (header.getItems().size() > 0)

{

item = (ZkumarItem)header.getItems().toArray()[0];

}

header.addToItems(item);

If an item already exists then you are trying to add the same item again. This will give duplicate item key.

the code header.addToItems(item); should be present in the else block.

Hope this resolves your problem.

Regards,

Priya

Answers (0)