AnsweredAssumed Answered

Getting exception when adding node with child-association

Question asked by mayankjoshi on Feb 2, 2007
Latest reply on Jan 20, 2008 by jharrop
Hi,
I am new to alfresco and kind of liking it a lot. Recently I got in this issue:

I have defined a custom type
First type:

<type name="my:a">
<title>A</title>
<parent>cm:folder</parent>
<associations>
  <child-association name="my:b">      
<target>         
<class>my:b</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</child-association>
</associations>
<mandatory-aspects>
<aspect>my:baseAspect</aspect>
</mandatory>
</type>

second type:
<type name="my:b">
<title>B</title>
<parent>cm:folder</parent>   
<mandatory-aspects>
<aspect>my:baseAspect</aspect>
</mandatory-aspects>
</type>

Also I have written a small jsp file to test this model.
ServletContext servletContext =this.getServletContext();
   ApplicationContext appContext = (ApplicationContext)WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
   Repository repository = (Repository)appContext.getBean("JCR.Repository");
   javax.jcr.Session mySession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
//Line#1:
Node rootNode = mySession.getRootNode();
//Line#2:
Node companyHome = rootNode.getNode("app:company_home");
//Line#3:
Node aNode = companyHome.addNode("A","my:a");
//Line#4:
Node bNode = programNode.addNode("B","my:b");

When //Line#4: is executed I get the below exception:
org.alfresco.error.AlfrescoRuntimeException: Cannot determine child association for node type '{alfresco/extension/myModel.xml}b within parent workspace://SpacesStore/605e23eb-b2ad-11db-9b78-6b973304f9e0
        at org.alfresco.jcr.item.NodeImpl.getNodeTypeChildAssocDefForParent(NodeImpl.java:243)
        at org.alfresco.jcr.item.NodeImpl.addNode(NodeImpl.java:181)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.alfresco.jcr.util.JCRProxyFactory$SessionContextInvocationHandler.invoke(JCRProxyFactory.java:130)
        at $Proxy73.addNode(Unknown Source)
        at org.apache.jsp.test_jsp._jspService(org.apache.jsp.test_jsp:137)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

I am not able to understand why i am getting this exception. A similar child-association is give in contentModel.xml and it works fine.

Mayank

Outcomes