Sorry, I should have given a full example of the problem code.
The following code fails on a fresh setup.
@Startup
@Singleton
public class JcrStartupSingleton {
@Resource(name = "jcr/repository", type = javax.jcr.Repository.class)
private Repository repository;
@PostConstruct
public void setupWorkspaces() throws RepositoryException {
final Session session = repository.login(new
SimpleCredentials("admin1", "".toCharArray()), "production");
try {
session.getRootNode().addNode("example");
session.save();
session.getWorkspace().createWorkspace("staging", "production");
} finally {
session.logout();
}
}
}
Gives an exception with a root cause of:
Caused by: javax.jcr.PathNotFoundException: /example
at
org.apache.jackrabbit.core.BatchedItemOperations.getNodeState(BatchedItemOperations.java:1456)
at
org.apache.jackrabbit.core.BatchedItemOperations.copy(BatchedItemOperations.java:387)
at
org.apache.jackrabbit.core.WorkspaceImpl.internalCopy(WorkspaceImpl.java:404)
at
org.apache.jackrabbit.core.WorkspaceImpl.clone(WorkspaceImpl.java:606)
at
org.apache.jackrabbit.core.WorkspaceImpl.createWorkspace(WorkspaceImpl.java:221)
at
au.projectx.jcr.JcrStartupSingleton.setupWorkspaces(JcrStartupSingleton.java:49)
Where line 49 is:
session.getWorkspace().createWorkspace("staging", "production");
-- Cory
On 05/08/2010, at 9:29 PM, Alexander Klimetschek wrote:
> On Thu, Aug 5, 2010 at 10:41, Cory Prowse <[email protected]> wrote:
>> Hi,
>>
>> I'm attempting to create a workspace from another srcWorkspace but it is
>> throwing a PathNotFoundException on a node that is a child of the root.
>>
>> This is on JackRabbit 2.1.0 deployed as a JCA.
>>
>> I am essentially doing the following:
>>
>> session = repository.login(new SimpleCredentials("admin1",
>> "".toCharArray()), "default");
>> session.getRootNode().addNode("/example", NodeType.NT_UNSTRUCTURED);
>> session.save();
>> workspace.createWorkspace("staging", "default");
>> session.logout();
>>
>> This throws a PathNotFoundException on "/example".
>>
>> Not sure what to do from here, can anyone provide possible causes?
>
> I guess if you look close, the exception is not thrown by
> createWorkspace but by the previous addNode() (or save()) operation.
> addNode() expects a relative path, so it should be:
>
> session.getRootNode().addNode("example", NodeType.NT_UNSTRUCTURED);
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> [email protected]