jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeroen Reijn <j.re...@onehippo.com>
Subject Re: javax.jcr.nodetype.ConstraintViolationException: No child node definition for ch
Date Tue, 22 Mar 2011 16:19:03 GMT
Hi raaja,

from what I can see this has to do with the nt:unstructured node which you
are trying to create underneath the 'Raaja' node.

Underneath a node of type nt:folder you can only add a child node that
extends the type nt:hierarchyNode (nt:file, nt:folder or nt:linkedFile) but
not a node of type nt:unstructured.

If you would change that or change the type of the Raaja node then you will
probably succeed.

At the below URL you can see the type hierarchy for the default JR 2.1 node
types:

http://svn.apache.org/repos/asf/jackrabbit/branches/2.1/jackrabbit-core/src/main/resources/org/apache/jackrabbit/core/nodetype/builtin_nodetypes.cnd

I hope this helps.

Regards,

Jeroen

On Thu, Mar 3, 2011 at 7:54 AM, graaja <raaja09@gmail.com> wrote:

> Hi,
>
> I am new to jackrabbit. I successfully created a node nt:folder and to that
> I uploaded a document. But now when I am trying to create a versionable
> node
> in the repository, I am failing to do so. Basing on the examples I wrote
> the
> below mentioned program but it is giving me the following error I tried a
> lot but failed. Please help me where I am going wrong. What I have to do to
> create a versionable node and can post documents with versions.
>
> javax.jcr.nodetype.ConstraintViolationException: No child node definition
> for ch
> ildNode found in node /Raaja
>        at
> org.apache.jackrabbit.rmi.server.ServerObject.getRepositoryException(
> ServerObject.java:109)
>        at
> org.apache.jackrabbit.rmi.server.ServerNode.addNode(ServerNode.java:8
> 2)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>        at java.lang.reflect.Method.invoke(Unknown Source)
>        at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
>        at sun.rmi.transport.Transport$1.run(Unknown Source)
>        at java.security.AccessController.doPrivileged(Native Method)
>        at sun.rmi.transport.Transport.serviceCall(Unknown Source)
>        at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
>        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown
> Sou
> rce)
>        at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown
> Sour
> ce)
>        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown
> Source
> )
>        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown
> Source)
>        at java.lang.Thread.run(Unknown Source)
>        at
> sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknow
> n Source)
>        at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
>        at sun.rmi.server.UnicastRef.invoke(Unknown Source)
>        at org.apache.jackrabbit.rmi.server.ServerNode_Stub.addNode(Unknown
> Sour
> ce)
>        at
> org.apache.jackrabbit.rmi.client.ClientNode.addNode(ClientNode.java:1
> 05)
>        at hello.main(hello.java:62)
>
>
> import java.io.File;
> import java.io.FileInputStream;
> import org.apache.jackrabbit.rmi.client.*;
> import javax.jcr.Repository;
> import javax.jcr.Session;
> import javax.jcr.Node;
> import javax.jcr.version.Version;
>
> public class hello
> {
> @SuppressWarnings("deprecation")
> public static void main(String args[]) throws Exception{
>
>     ClientRepositoryFactory factory = new ClientRepositoryFactory();
>     Session jcrSession=null;
>     String wspName;
>     Repository rep
> =factory.getRepository("rmi://localhost/jackrabbit.repository");
>     System.out.println( "------ "+rep);
>
>     final String baseUrl =
> "http://localhost:8080/jackrabbit-webapp-2.1.3/server";
>     // Source file to upload:
>     File f = new File("D:/1.doc");
>     String name="Raaja";
>     String fileName="1.doc";
>
>     try{
>
>          jcrSession = rep.login(new SimpleCredentials("user",
> "".toCharArray()),"default");
>          wspName = jcrSession.getWorkspace().getName();
>
>
>          Node root = jcrSession.getRootNode();
>        System.out.println( "------ "+wspName);
>        System.out.println( "------ "+root);
>
>
>        Node node = root;
>        if (!node.hasNode(name)) {
>                  node.addNode(name, "nt:folder");
>            }
>        node = node.getNode(name);
>        Node n = node.addNode("childNode", "nt:unstructured");
>        n.addMixin("mix:versionable");
>        jcrSession.save();
>        Version firstVersion = n.checkin();
>        //add new version
>        Node child = n.getNode("childNode");
>        child.checkout();
>        jcrSession.save();
>        child.checkin();
>        if (!child.hasNode(fileName)) {
>             Node file = child.addNode(fileName, "nt:file");
>             final Node resource = file.addNode("jcr:content",
> "nt:resource");
>             resource.setProperty("jcr:data", new FileInputStream(f));
>        }
>        child.checkout();
>
>        jcrSession.save();
>             }
>
>             catch(Exception ex){
>              ex.printStackTrace();
>             }
>             finally {
>                   if (jcrSession != null) {
>                   jcrSession.logout();
>             }
> }
>
>
>        }
> }
>
> Thanking you.
> --raaja. g
>
> --
> View this message in context:
> http://jackrabbit.510166.n4.nabble.com/javax-jcr-nodetype-ConstraintViolationException-No-child-node-definition-for-ch-tp3332839p3332839.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message