I found an error on my application when I try to create multiple nodes on Alfresco. I use Java Custom Webscripts. I want to create 20.000 new nodes with documents on a while bucle. I throw this code multiple times and all works ok. I have created 100.000 nodes. But when I thrown another time the code, an error broke my execution. I found in a log this:EXCEPTION: org.springframework.dao.DataIntegrityViolationException: Detected stale node entry: NodeVersionKey [nodeId=373526, version=8] (now [NodeVersionKey [nodeId=373526, version=11]]The code try to create this node multiple times, but the exception occurs again and again.When occurs this exceptions? What's may be the cause that changes the version from 8 to 11?I add my code for more information about the problem…This is my code, when I create a node:
NodeRef nodeRef = null;
try {
properties.put(ContentModel.PROP_NAME, name);
nodeRef = getNodeService().createNode(
parent,
ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
type,
properties).getChildRef();
if (nodeRef!=null) {
QName CUSTOM_ASPECT_QNAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.aspectTitled);
Map<QName,Serializable> aspectValues = new HashMap<QName,Serializable>();
aspectValues.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.titleProperty), title);
aspectValues.put(QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, Constants.descriptionProperty), description);
getNodeService().addAspect(nodeRef, CUSTOM_ASPECT_QNAME, aspectValues);
}
And inside the while, I do a RetryingTransactionCallback to create each node each time.
boolean readonly = false;
boolean requiresNew = true
RetryingTransactionCallback<Object> txnWork = new RetryingTransactionCallback<Object>() {
public Object execute() throws Throwable {
Create the node…
}
};
TransactionService transactionService = serviceRegistry.getTransactionService();
return transactionService.getRetryingTransactionHelper().doInTransaction(txnWork, readonly, requiresNew);
Thanks a lot!