In Javascript, I can use the addNode() method to add an existing node to a new space. But in Java if I try to do the same thing with addChild(), I get an error:
org.alfresco.service.cmr.repository.DuplicateChildNodeNameException: Duplicate child name not allowed:
Is this action allowed in Javascript but not in Java? What do I need to do to make it work with Java?
Yes you can use the javascript API from Java, you use the script service to run a script. But why bother? The Java API is the one to use and can do everything the Script API can do and more.
Your error is that you are trying to create a duplicate which is not allowed.
Sort out the parameters to your java call and it will work.
Yes, you are right. There were duplicates in the same space. But they were duplicates in name only. The nodes were located in different locations but they happened to have the same name. It makes me wonder why Alfresco considers nodes with only the same name as duplicates even if their node references and locations are different.