Announcement Announcement Module
No announcement yet.
how can I unbind one entry from ldap Directory? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • how can I unbind one entry from ldap Directory?


    I want to delete one entry from ldap directory but I couldn't delete it ,and no error occurs,so what is the problem??

    my code is:

     ContactDTO newContactDTO = new ContactDTO();
    and this is my deleteContact method:

    public void deleteContact(ContactDTO contactDTO) {
    		DistinguishedName newContactDN = new DistinguishedName();
    		newContactDN.add("cn", contactDTO.getCommonName());
    Last edited by minakari; Aug 25th, 2007, 04:01 AM.

  • #2
    First of all, please use code tags when posting code.

    Anyway, as stated in the DirContext javadocs, unbind does not throw any exception if the actual node you are trying to remove does not exist (only if an intermediate node does not exist).

    You are probably supplying an invalid DN, possibly the reason being that you don't add any 'people' node, e.g. 'ou=People'.
     DistinguishedName newContactDN = new DistinguishedName();
     newContactDN.add("ou", "People");
     newContactDN.add("cn", contactDTO.getCommonName());


    • #3
      any way to get unbind to error if entry wasn't there

      I've read this thread and the comments above from Mattias and understand / agree that the way unbind is meant to work is that no error is thrown if the entry being unbind didn't exist anyway. This works ok for my current requirements but I'd still like the ability to set a boolean that would cause the unbind to fail if the entry wasn't even there.

      It seems like if I want to check that an entry was in fact deleted currently, I have to do a lookup first and then delete if there and alert if not there. I don't recall how the underlying jndi unbind (or similarly named operation) works but feel that if the spring ldap is swallowing an exception when the entry is not there, I'd like control over there.


      Tony Obermeit


      • #4
        Spring LDAP does not swallow any exception in this operation. The behavior is the default one, as described in the Context javadocs.

        We could provide a method that takes a boolean, performing the lookup as you describe if desired, but I do think the case is too specific to have a special operation.

        Compare this to issuing a DELETE statement to a relational database. While the statement does return the number of rows affected by the operation you will still not get any exception if no entry matches the criteria.


        • #5
          Thanks Matthias,

          Appreciate you taking the time to give the quick reply. If no exception is being swallowed, I'm very happy. With database deletes you can access a value that gives you the number of rows affected by the sql statement. I agree it would not be worth the effort to add a boolean to do a separate lookup, if I want that overhead, I can easily code it myself.

          Thanks again. You guys rock!