问题
Spring LdapRepository save() method throws exception when I'm trying to update an existing object in LDAP database.
org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException: ERR_250_ENTRY_ALREADY_EXISTS
What method should I use to update existing ldap objects?
Person class:
@Entry(objectClasses = { "inetOrgPerson", "organizationalPerson", "person", "top" })
public class Person implements Serializable {
public Person() {
}
@Id
private Name dn;
@Attribute(name = "cn")
@DnAttribute(value = "cn")
@JsonProperty("cn")
private String fullName;
@Attribute(name = "uid")
private String uid;
private String mail;
@Attribute(name = "sn")
private String surname;
//setters and getters
}
Person repo interface:
public interface PersonRepo extends LdapRepository<Person> {
}
That's how I'm updating person:
personRepo.save(person);
回答1:
Default implementation for Spring LDAP repositories is SimpleLdapRepository, that checks the property annotated with @Id
to determine if the objects is new - and perform create, or old - and perform update.
I'm guessing that Person.dn
is null
when you're trying to perform update.
You also can take the control over this by implementing org.springframework.data.domain.Persistable
and place your logic in the isNew()
method.
See the implementation details.
来源:https://stackoverflow.com/questions/33288011/ldaprepository-update-spring-ldap