我複製使用session.getWorkspace().copy(sourceNode.getPath(), destinationNode.getPath())
節點標識,同時刪除
此操作爲即時據我所知變化堅持兔崽子節點未找到。但是,當我試圖使用session.getNodeByIdentifier("nodeId of copied node")
來獲取複製的節點以刪除它時,它會給出ItemNotFoundException。造成該錯誤的原因是複製節點失去了複製過程中的mix:referenceable
屬性,導致getNodeByIdentifier失敗。
問題是如何將mix:referenceable
屬性設置爲複製節點,因爲我無法在複製操作後從會話中獲取節點。有人可以幫我解決這個問題嗎?
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();
例外:在線程 「主要」 javax.jcr.InvalidItemStateException
例外:無法更新過時的項目: item.save() at org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(ServerO bject.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.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(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) at sun.rmi.transport.Transport $ 1.run(Transport.java:197) at 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) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.tcp.TCPTransport $ ConnectionHandler。運行(TCPTransport.java:682) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617) at java。 lang.Thread.run(Thread.java:748) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteC all.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(來源不明) 在org.apache.jackrabbit.rmi.client.ClientSession.save(ClientSession.java:272)
請注意,我用的JCR 2.0另外,如果我將代碼更改爲,代碼工作正常,但我無法從會話中找到節點標識符以刪除相同的問題。
我有時候會反感。謝謝你的答案。 – Gandhi