jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cory Prowse (JIRA)" <j...@apache.org>
Subject [jira] Commented: (JCR-2701) createWorkspace throws PathNotFoundException
Date Sat, 23 Oct 2010 02:55:20 GMT

    [ https://issues.apache.org/jira/browse/JCR-2701?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12924112#action_12924112
] 

Cory Prowse commented on JCR-2701:
----------------------------------

I've followed through the logic and it seems to me that the root cause is that calling save
on a session does not persist to the underlying datastore due to it being part of a container
managed transaction.  However it seems the createWorkspace process has an incorrect assumption
on state, centred I believe around XAItemStateManager.

The reason I think this is a problem is threefold:
(1) - When calling save on a XASession that is part of a running transaction, it will not
persist to the underlying datastore and instead merge changes together for the final commit
(2). in WorkspaceImpl.createWorkspace(String,String), it uses the _CURRENT_ session to iterate
through all children of the root node, so that it can then issue a clone for each child node
name to the new workspace.
(3). in WorkspaceImpl.clone() it creates a _NEW_ session on the source workspace to copy nodes
from.

Since (1) means the changes are not available to other sessions, (2) sees the "saved" nodes,
but (3) does not and so fails with the PathNotFoundException.

So a workaround for the problem is to use bean managed transactions which commit the user
transaction after the save, and before the creation of a new workspace, which I have verified
works.

However to me it seems the assumption in WorkspaceImpl.clone could cause other problems where
an overlying transaction is in place, causing it to attempt to copy unpersisted (but saved!)
nodes.

> createWorkspace throws PathNotFoundException
> --------------------------------------------
>
>                 Key: JCR-2701
>                 URL: https://issues.apache.org/jira/browse/JCR-2701
>             Project: Jackrabbit Content Repository
>          Issue Type: Bug
>          Components: jackrabbit-jca
>    Affects Versions: 2.1.1
>         Environment: Jackrabbit is deployed using released JCA on Glassfish 3.0.1
>            Reporter: Cory Prowse
>         Attachments: JCR-2701.zip
>
>
> The following code throws a PathNotFoundException:
> ---
> package au.jcr;
> import javax.annotation.PostConstruct;
> import javax.annotation.Resource;
> import javax.ejb.Singleton;
> import javax.ejb.Startup;
> import javax.jcr.Repository;
> import javax.jcr.RepositoryException;
> import javax.jcr.Session;
> import javax.jcr.SimpleCredentials;
> @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("admin", "".toCharArray()),
"production");
>         try {
>             session.getRootNode().addNode("example");
>             session.save();
>             // Exception is thrown here (is line 27)
>             session.getWorkspace().createWorkspace("staging", "production");
>         } finally {
>             session.logout();
>         }
>     }
> }
> ---
> javax.ejb.EJBException: javax.ejb.CreateException: Initialization failed for Singleton
JcrStartupSingleton
>         at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:698)
> ...
> Caused by: javax.ejb.CreateException: Initialization failed for Singleton JcrStartupSingleton
>         at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:528)
> ...
> 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.jcr.JcrStartupSingleton.setupWorkspaces(JcrStartupSingleton.java:27)
> ...

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message