【问题标题】:LdapRepository update spring-ldapLdapRepository 更新 spring-ldap
【发布时间】:2015-10-24 02:50:41
【问题描述】:

当我尝试更新 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
}

个人回购界面:

public interface PersonRepo extends LdapRepository<Person> {
}

这就是我更新人的方式:

personRepo.save(person);

【问题讨论】:

  • 请提供代码以帮助查明问题。
  • @marthursson,已更新

标签: java spring ldap spring-ldap


【解决方案1】:

Spring LDAP 存储库的默认实现是SimpleLdapRepository,它检查带有@Id 注释的属性以确定对象是 - 并执行创建或 - 并执行更新。

当您尝试执行更新时,我猜Person.dnnull

您还可以通过实现org.springframework.data.domain.Persistable 来控制它,并将您的逻辑放在isNew() 方法中。

请参阅implementation details

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2018-04-15
    • 2014-01-26
    相关资源
    最近更新 更多