Node Id of copied Node in Jackrabbit not found on delete

I copied a node to Jackrabbit using session.getWorkspace().copy(sourceNode.getPath(), destinationNode.getPath())

Changes to this operation are saved instantly as far as I know. But when I tried to get the copied node to delete it with session.getNodeByIdentifier("nodeId of copied node")

, it gives an ItemNotFoundException. The reason for this error is that the copied node loses the property mix:referenceable

during copying, which causes getNodeByIdentifier to fail.

The question is how to set the property mix:referenceable

to copy a node as I cannot get the node from the session after the copy operation. Can anyone help me with this?

UPDATE:

CODE:

    Node srcNode = session.getNodeByIdentifier("SOURCE_NODE_ID");
    if(srcNode == null) {
        System.out.println("File not found");
    }

    Node rootNode = session.getRootNode();
    Node appNode  = rootNode.getNode("JACKRABBIT");
    Node destNode = appNode.addNode("Copy_Test_"+System.currentTimeMillis(),"nt:file");

    session.getWorkspace().copy(srcNode.getPath(),destNode.getPath());
    destNode.addMixin(MIX_VERSIONABLE);
    destNode.addMixin(MIX_LOCKABLE);
    destNode.addMixin(MIX_REFERENCEABLE);
    destNode.addNode(DMSConstants.RESOURCE_NODE,"nt:unstructured");
    session.refresh(true);
    session.save();

      

AN EXCEPTION:

Exception on thread "main" javax.jcr.InvalidItemStateException: Unable to update deprecated item: item.save () at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException (ServerObject.java:111) at org.apache.jackrabbit. rmi.server.ServerSession.save (ServerSession.java:265) at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.javaImage.Plus) at sun.reflect.Delegorccess DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke (Method.java:498) at sun.rmi.server.UnicastServerRef.dispatch (UnicastServerRef.java:346) at sun.rmi.transport.Transport $ 1. run (Transport.java:200) to sun.rmi.transport.Transport $ 1.run (Transport.java:197) to java.security.AccessController.doPrivileged (native method) at sun.rmi.transport.Transport.serviceCall (Transport.java:196) at sun.rmi.transport.tcp.TCPTransport.handleMessages (TCPTransport.java:568) at sun.rmi.transport.tcp. TCPTransport $ ConnectionHandler.run0 (TCPTransport.java:826) at sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler.lambda $ run $ 0 (TCPTransport.java:683) in java.security.AccessController.doPrivileged (native method) at sun .rmi.transport.tcp.TCPTransport $ ConnectionHandler.run (TCPTransport.java:682) to java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) to java.util.concurrent.ThreadPoolExecutor (ThreadPoolExecutor. .java: 617) at java.lang.Thread.run (Thread.java:748) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer (StreamRemoteCall.java:276) at sun.rmi.transport.StreamRemoteCall.executeCall (StreamRemoteCall.java:253) at sun.rmi.server.UnicastRef.invoke (UnicastRef.java:162) at org.apache.jackrabbit.rmi.server.ServerXASession_Stub.save (Unknown source) at org. apache.jackrabbit.rmi.client.ClientSession.save (ClientSession.java:272)

Please note that I am using JCR 2.0. Also if I change the code to session.refresh(false)

, the code works fine, but I was unable to find the node id from the session to remove the same as my original problem.

+1


source to share


2 answers


Why are you creating a node at the destination and then copying it to the same location? I believe the deprecated exception is because the call has copy

updated the underlying node, making your link destNode

obsolete / obsolete.

Just remove addNode

, then do something like ...



String destPath = "Copy_Test_" + System.currentTimeMillis()";
session.getWorkspace().copy(srcNode.getPath(), destPath);
Node destNode = session.getPath(destPath);

      

+1


source


As @TedTrippin pointed out, the problem was creating the destination node before the copy, which was not required. As part of the copy, a node is created. So my final working code looks like this:



Node srcNode = session.getNodeByIdentifier("SOURCE_NODE_ID");
if(srcNode == null) {
    System.out.println("File not found");
}

Node rootNode = session.getRootNode();
Node appNode  = rootNode.getNode("JACKRABBIT");    
String destNodeName = "Copy_Test";  
session.getWorkspace().copy(srcNode.getPath(),appNode.getPath() + "/" + destNodeName);
Node destNode = appNode.getNode(destNodeName);
destNode.addMixin(MIX_VERSIONABLE);
destNode.addMixin(MIX_LOCKABLE);
destNode.addMixin(MIX_REFERENCEABLE);    
session.refresh(true);
session.save();

      

0


source







All Articles