LdapRepository更新spring-ldap [英] LdapRepository update spring-ldap

查看:382
本文介绍了LdapRepository更新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);

推荐答案

Spring LDAP存储库的默认实现为

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.dnnull.

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.

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆