On 2010-03-03 11:41, Stefan Guggisberg [via Jackrabbit] wrote:
hi nils,

On Wed, Mar 3, 2010 at 11:24 AM, Nils Weinander
<[hidden email]
<http://n4.nabble.com/user/SendEmail.jtp?type=node&node=1576362&i=0>>
wrote:

 >
 > Probably a stupid newbie question, but here it goes. I use Jackrabbit
2.0.0
 > through Spring-JCR. I want to use the jcr:title and jcr:description
 > properties from the mix:title mixin. The significant portion of the code
 > looks like this:
 >
 >   Node containerNode = rootNode.addNode(id,
jcrConstants.getNT_FOLDER());
 >   containerNode.addMixin("mix:title");
 >   containerNode.setProperty("jcr:title", title);
 >   containerNode.setProperty("jcr:description", description);
 >   session.save();

you're sure that 'session' is the one where you got 'rootNode' from?

Yes, it is the same session

did you try to run a simple test case which just uses the jcr api
(without any blackbox magic on top of if ;)? see jackrabbit-jcr-tests
for examples.

A simple test case works:

        @Test
        public void testSetProperty() throws LoginException, 
RepositoryException {
                Repository repository = null;
                Map<String,String> parameters = new HashMap<String,String>();
parameters.put("org.apache.jackrabbit.repository.conf", "C:/Users/nils.weinander/workspace/fofu-prototype/src/main/resources/repository.xml"); parameters.put("org.apache.jackrabbit.repository.home", "C:/Users/nils.weinander/tmp/repo"); for (RepositoryFactory factory : ServiceLoader.load(RepositoryFactory.class)) {
                        repository = factory.getRepository(parameters);
                        if (repository != null) {
                                break;
                        }
                }
                //Repository repository = new TransientRepository();
Credentials credentials = new SimpleCredentials("admin", "admin".toCharArray());
                Session session = repository.login(credentials);
Node testNode = session.getRootNode().addNode("TEST-NODE", NodeType.NT_FOLDER);
                testNode.addMixin("mix:title");
                testNode.setProperty("jcr:title", "TEST-TITLE");
                session.save();
                assertTrue(testNode.hasProperty("jcr:title"));
                Property property = testNode.getProperty("jcr:title");
                assertNotNull(property);
                assertEquals("TEST-TITLE", property.getString());
                session.logout();
        }

The logs differ slightly, I can see that I get a TransientRepository
with the simple test case.

So, something is different when the repository is instantiated
by Spring. Question is what...

--
mogul | nils weinander |
hudiksvallsgatan 4 113 30 stockholm sweden |
+46 8 4100 6456 | +46 709 78 28 37 |
[email protected] | skype: nils.weinander |
www.mogul.com

Reply via email to