We've found that when you create a new node, you often have to save the
parent, rather than the new node itself, to get it to persist to JCR. Here's
a bit of sample code from one of our utility scripts:
Content collection = page.createContent(
"contentParagraph",
ItemType.CONTENTNODE.getSystemName() );
page.save();
Content paragraph = collection.createContent( "0",
ItemType.CONTENTNODE.getSystemName() );
paragraph.setNodeData("content",
valueFactory.createValue( text ));
MetaData meta = paragraph.getMetaData();
meta.setTemplate( "texasEditor" );
collection.save();
Magnolia - User mailing list-2 wrote:
>
> Hi All, can you help me with this behaviour? No idea why it fails to
> create a new content node...
>
>
> // create path for this node under "data". It works, path is created and
> // visible in JCR Browser
> // basePathis "/folder1/folder2"
> final Content baseNode = createPath(basePath, hm);
>
> // save this (persistently apply changes to repo)
> baseNode.save();
>
> // I have a data type called "myType".
> // So I want to create a new Content Type under "basePath".
> Content newNode = baseNode.createContent("test", "myType");
>
> // set name
> newNode.createNodeData("name").setValue("test");
>
> // save children
> newNode.save();
>
> at this point I have an exception:
>
> "/folder1/folder2/test: cannot save a new item."
>
>
>
> Any Idea?
>
> Thanks..
> M.
>
>
> ----------------------------------------------------------------
> for list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> ----------------------------------------------------------------
>
>
--
View this message in context:
http://www.nabble.com/New-Content-Node-fails...-tp20382126p20382240.html
Sent from the Magnolia - User mailing list archive at Nabble.com.
----------------------------------------------------------------
for list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
----------------------------------------------------------------