Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8952265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:50:18+00:00 2026-06-15T13:50:18+00:00

I want to add a node under a node using ObjectContentManager. I am able

  • 0

I want to add a node under a node using ObjectContentManager.

I am able to add a single node using ObjectContentManager , using

Pojo1 p1 = new Pojo1 ();
p1 .setPath("/p1");
p1 .setName("p_3");
p1 .insert(p1);
ocm.save();

Now under this node I want to add another node of Pojo2 class.
I have written a code , but it is giving me exception.

Pojo2 p2 = new Pojo2 ();
p2.setPath("/p1/p2");
p2.setName("p_3");
p2.insert(p2);
ocm.save();

But this is giving me exception.

org.apache.jackrabbit.ocm.exception.ObjectContentManagerException: Cannot create new node of type nt:pojo1 from mapped class class com.sapient.Pojo1; nested exception is javax.jcr.nodetype.ConstraintViolationException: No child node definition for p2 found in node /p1

How i can achieve this?
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:50:19+00:00Added an answer on June 15, 2026 at 1:50 pm

    If you look at the OCM test classes there’s a good example of how this should be configured:
    A.java

    @Node(jcrMixinTypes="mix:lockable" )
    public class A
    {
    @Field(path=true) private String path;
    @Field private String a1;
    @Field private String a2;
    @Bean(jcrType="nt:unstructured", jcrOnParentVersion="IGNORE") private B b;
    

    The Bean Annotation is what’s used to indicate that your persisting the object as another node rather than a property.

    Here’s the test code that adds the B object the A object AnnotationBeanDescriptorTest.java

    ObjectContentManager ocm = getObjectContentManager();
    // ------------------------------------------------------------------------
    // Create a main object (a) with a null attribute (A.b)
    // ------------------------------------------------------------------------
    A a = new A();
    a.setPath("/test");
    a.setA1("a1");
    ocm.insert(a);
    ocm.save();
    
    // ------------------------------------------------------------------------
    // Retrieve
    // ------------------------------------------------------------------------
    a = (A) ocm.getObject("/test");
    assertNotNull("Object is null", a);
    assertNull("attribute is not null", a.getB());
    
    B b = new B();
    b.setB1("b1");
    b.setB2("b2");
    a.setB(b);
    
    ocm.update(a);
    ocm.save();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create new node of BeanTreeView, and when I add some node
I got the string from xml file.now i want to Add the new node
If I want to add, update or delete node in the xml using c#,
I have problem, when I want add Node to my GUI from other Thread.
I want to add a child node to an element in XmlDocument. For the
I want to dynamically add links to my pages something like this: foreach (Node
I have a several processes node.js. I want to only add one string to
I want add new Feed item on entity persist and update. I write this
(5)Root (3)-------^--------(7) (2)---^----(5) ^-----(8) I want to add node with data 5 in this
I want to add node at specific index in DevExpress TreeList . I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.