Index: modeshape-jcr/src/main/java/org/modeshape/jcr/SessionCache.java =================================================================== --- modeshape-jcr/src/main/java/org/modeshape/jcr/SessionCache.java (revision 1720) +++ modeshape-jcr/src/main/java/org/modeshape/jcr/SessionCache.java (working copy) @@ -26,6 +26,7 @@ package org.modeshape.jcr; import java.lang.ref.SoftReference; import java.security.AccessControlException; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -1539,10 +1540,20 @@ class SessionCache { } else { result = node.createChild(name, primaryTypeProp, nodeDefinitionProp); } + + JcrNode jcrNode = (JcrNode)result.getPayload().getJcrNode(); + + // Fix the jcr:created protected property for nt:hierarcyNode (and descendants) + boolean isHierarchyNode = primaryType.isNodeType(JcrNtLexicon.HIERARCHY_NODE); + if (isHierarchyNode) { + JcrValue value = jcrNode.valueFrom(Calendar.getInstance()); + jcrNode.editor().setProperty(JcrLexicon.CREATED, value, false); + } + // The postCreateChild hook impl should populate the payloads // Finally, return the jcr node ... - return (JcrNode)result.getPayload().getJcrNode(); + return jcrNode; } catch (ValidationException e) { throw new ConstraintViolationException(e.getMessage(), e); } catch (RepositorySourceException e) { Index: modeshape-jcr/src/test/java/org/modeshape/jcr/JcrSessionTest.java =================================================================== --- modeshape-jcr/src/test/java/org/modeshape/jcr/JcrSessionTest.java (revision 1720) +++ modeshape-jcr/src/test/java/org/modeshape/jcr/JcrSessionTest.java (working copy) @@ -56,14 +56,14 @@ import javax.jcr.ValueFactory; import javax.jcr.nodetype.NodeType; import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; -import org.modeshape.graph.ExecutionContext; -import org.modeshape.graph.JaasSecurityContext; -import org.modeshape.graph.property.NamespaceRegistry; -import org.modeshape.graph.property.Path; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import org.modeshape.graph.ExecutionContext; +import org.modeshape.graph.JaasSecurityContext; +import org.modeshape.graph.property.NamespaceRegistry; +import org.modeshape.graph.property.Path; /** * @author jverhaeg @@ -423,4 +423,14 @@ public class JcrSessionTest extends AbstractSessionTest { // Expected } } + + @Test + public void shouldAddCreatedPropertyForHierarchyNodes() throws Exception { + // q.v. MODE-694 + Node folderNode = session.getRootNode().addNode("folderNode", "nt:folder"); + assertThat(folderNode.hasProperty("jcr:created"), is(true)); + + Node fileNode = folderNode.addNode("fileNode", "nt:file"); + assertThat(fileNode.hasProperty("jcr:created"), is(true)); + } }