cancel
Showing results for 
Search instead for 
Did you mean: 

Creating version - problem

tde
Champ in-the-making
Champ in-the-making
I'm trying to create a node and then adding two versions to it. Code goes like this:

ChildAssociationRef childAssoc = nodeService.createNode(parent, ContentModel.ASSOC_CONTAINS, assocQName, ContentModel.TYPE_CONTENT, properties);
NodeRef newNode = childAssoc.getChildRef();

then adding some content to it:

ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.putContent(stream);

Later I'm fetching that same node:

NodeRef node = nodeService.getChildByName(parent, ContentModel.ASSOC_CONTAINS, name);

and adding a version

versionService.createVersion(node, null);

and some new content

ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
writer.setMimetype(mimetype);
writer.putContent(stream);

All goes well by here.

But when I'm versioning for second time problems occur. I fetch the same node with same call to NodeService.getChildByName, node is found but on calling VersionService.createVersion (with same params) I get exception:


Exception in thread "main" org.alfresco.service.cmr.version.VersionServiceException: 02110001 The current version label of the node does not exist in the version history.
   at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:289)
   at org.alfresco.repo.version.Version2ServiceImpl.createVersion(Version2ServiceImpl.java:139)

All this code is happening in same transaction.

Can someone point to me what I'm doing wrong?

Thank you.
1 REPLY 1

kbrady
Champ in-the-making
Champ in-the-making
The error could be occurring because a versionProperties object is not passed to the createVersion() method for the second version. You may need to specify if the new version is a MAJOR or MINOR version increment


   Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
   versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
   versionService.createVersion(nodeRef, versionProperties);