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.