当我尝试更新 LDAP 数据库中的现有对象时,Spring LdapRepository save() 方法抛出异常。
org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException: ERR_250_ENTRY_ALREADY_EXISTS
我应该使用什么方法来更新现有的 ldap 对象?
人员类别:
@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
}
人员 repo 接口(interface):
public interface PersonRepo extends LdapRepository<Person> {
}
这就是我更新人员的方式:
personRepo.save(person);
最佳答案
Spring LDAP 存储库的默认实现是 SimpleLdapRepository ,它检查用 @Id
注释的属性,以确定对象是新 - 并执行创建,还是旧 - 并执行更新。
我猜测当您尝试执行更新时,Person.dn
为 null
。
您还可以通过实现org.springframework.data.domain.Persistable
来控制它,并将逻辑放在isNew()
方法中。
关于java - LdapRepository 更新 spring-ldap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288011/