LdapRepository更新spring-ldap [英] LdapRepository update spring-ldap
问题描述
当我尝试更新LDAP数据库中的现有对象时,Spring LdapRepository save()方法将引发异常.
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
我应该使用哪种方法来更新现有的ldap对象?
What method should I use to update existing ldap objects?
人员班级:
@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
}
人员回购界面:
public interface PersonRepo extends LdapRepository<Person> {
}
这就是我更新人的方式:
That's how I'm updating person:
personRepo.save(person);
推荐答案
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.
当您尝试执行更新时,我猜测Person.dn
是null
.
I'm guessing that Person.dn
is null
when you're trying to perform update.
您还可以通过实现org.springframework.data.domain.Persistable
来控制此操作,并将逻辑放置在
You also can take the control over this by implementing org.springframework.data.domain.Persistable
and place your logic in the isNew()
method.
请参见 查看全文