You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by saurav gangulyy <vi...@yahoo.com> on 2008/05/21 10:17:21 UTC

How to disallow node from having same name siblings?

Hi,

Is there anyway to prevent node from having same name siblings?

Regards,
Vijay
-- 
View this message in context: http://www.nabble.com/How-to-disallow-node-from-having-same-name-siblings--tp17358205p17358205.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: How to disallow node from having same name siblings?

Posted by saurav gangulyy <vi...@yahoo.com>.
Hi,
     I get following exception at line 5 on execution of code:
          1    Repository repository = new TransientRepository();	
	  2    Session ses = repository.login(new
SimpleCredentials("username","password".toCharArray()));
          3  Node node = root.addNode("par7", "nt:folder");
	  4 Node child = node.addNode("child1", "nt:file");    
	  5 ses.save();
javax.jcr.nodetype.ConstraintViolationException: /par7/child1: mandatory
child node {http://www.jcp.org/jcr/1.0}content does not exist
Can u plz tell reason for the same?

 Regards,
Vijay 

Jukka Zitting wrote:
> 
> Hi,
> 
> On Wed, May 21, 2008 at 11:55 AM, saurav gangulyy
> <vi...@yahoo.com> wrote:
>> Can u plz illustrate this with example code?
>> Node nod = root.addNode("par7");
>> Node chld = nod.addNode("chld1");
>>
>> wht do I need to do in order to ensure 'chld1' can't be added again?
> 
> You can define a custom node type for the "par7" node or use a
> standard one like nt:folder that doesn't allow same name siblings.
> 
> For example:
> 
>     Node node = root.addNode("par7", "nt:folder");
>     Node child = node.addNode("child1", "nt:file");
> 
> Note that nt:folder only allows nt:hierarchyNode children, so you need to:
> 
> a) make your content fit the nt:folder/nt:file structure (not that
> nt:file allows an unstructured jcr:content child node),
> b) add custom node types that extend nt:hierarchyNode, or
> c) use a custom node type instead of nt:folder.
> 
> BR,
> 
> Jukka Zitting
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-disallow-node-from-having-same-name-siblings--tp17358205p17364196.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: How to disallow node from having same name siblings?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Wed, May 21, 2008 at 11:55 AM, saurav gangulyy
<vi...@yahoo.com> wrote:
> Can u plz illustrate this with example code?
> Node nod = root.addNode("par7");
> Node chld = nod.addNode("chld1");
>
> wht do I need to do in order to ensure 'chld1' can't be added again?

You can define a custom node type for the "par7" node or use a
standard one like nt:folder that doesn't allow same name siblings.

For example:

    Node node = root.addNode("par7", "nt:folder");
    Node child = node.addNode("child1", "nt:file");

Note that nt:folder only allows nt:hierarchyNode children, so you need to:

a) make your content fit the nt:folder/nt:file structure (not that
nt:file allows an unstructured jcr:content child node),
b) add custom node types that extend nt:hierarchyNode, or
c) use a custom node type instead of nt:folder.

BR,

Jukka Zitting

Re: How to disallow node from having same name siblings?

Posted by saurav gangulyy <vi...@yahoo.com>.
Hi,

Can u plz illustrate this with example code?
Node nod = root.addNode("par7");
Node chld = nod.addNode("chld1");

wht do I need to do in order to ensure 'chld1' can't be added again?

Regards,
Vijay


saurav gangulyy wrote:
> 
> Hi,
> 
> Is there anyway to prevent node from having same name siblings?
> 
> Regards,
> Vijay
> 

-- 
View this message in context: http://www.nabble.com/How-to-disallow-node-from-having-same-name-siblings--tp17358205p17358876.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: How to disallow node from having same name siblings?

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Wed, May 21, 2008 at 11:17 AM, saurav gangulyy
<vi...@yahoo.com> wrote:
> Is there anyway to prevent node from having same name siblings?

Yes. Whether or not same name siblings are allowed is controlled by
the node type of the parent node.

BR,

Jukka Zitting