diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java index 6f252f58..4a153698 100644 --- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java +++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java @@ -91,17 +91,27 @@ public class LdapDaoITest extends AbstractLdapTemplateIntegrationTest } - public void testLoadsReferencedEntities() + public void testLoadsReferences() { ITestRole webUser = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class); ldapDao.create(testPerson); webUser.setMembers(new ITestPerson[]{testPerson}); ldapDao.update(webUser); ITestRole updated = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class); - LOGGER.debug(updated); + LOGGER.debug("Updated:" + updated); Assert.assertTrue(ArrayUtils.contains(updated.getMembers(), testPerson)); } + public void testLoadsReferences_brokenReferenceReturnedAsNull() + { + ITestRole webUser = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class); + webUser.setMembers(new ITestPerson[]{testPerson}); + ldapDao.update(webUser); + ITestRole updated = (ITestRole) ldapDao.findByNamingAttribute("webUser", ITestRole.class); + Assert.assertNotNull(updated); + LOGGER.debug(updated); + } + public void testFindByDn() { diff --git a/spring-ldap-odm/src/itest/resources/beans.xml b/spring-ldap-odm/src/itest/resources/beans.xml index ac6fc68e..64c118a0 100644 --- a/spring-ldap-odm/src/itest/resources/beans.xml +++ b/spring-ldap-odm/src/itest/resources/beans.xml @@ -1,6 +1,13 @@ - - + @@ -17,25 +24,25 @@ - + - + - - - + diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java index 1ac218d7..069b31ce 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java @@ -68,6 +68,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper Object beanPropertyValue = typeConverter.convertIfNecessary( new AttributeWrapper(attribute).getAllAsObject(), attributeType); propertySetters.get(beanPropertyName).invoke(instance, beanPropertyValue); + } catch (TypeMismatchException e) { diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferencedEntryEditor.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferencedEntryEditor.java index f55dafb0..707cd6aa 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferencedEntryEditor.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferencedEntryEditor.java @@ -9,11 +9,13 @@ import org.springframework.ldap.core.LdapTemplate; import org.springframework.ldap.core.DistinguishedName; import org.springframework.ldap.odm.mapping.MappingException; import org.springframework.ldap.odm.mapping.ObjectDirectoryMapper; +import org.springframework.ldap.NameNotFoundException; import java.beans.PropertyEditorSupport; -/** ReferencedEntryEditor is responsible for converting references in an object - * directory map from distinguished name strings to the target type and vice versa. +/** + * ReferencedEntryEditor is responsible for converting references in an object + * directory map from distinguished name strings to the target type and vice versa. */ public class ReferencedEntryEditor extends PropertyEditorSupport { @@ -30,7 +32,9 @@ public class ReferencedEntryEditor extends PropertyEditorSupport this.objectDirectoryMapper = objectDirectoryMapper; } - /** Builds a distinguished name from the instance value */ + /** + * Builds a distinguished name from the instance value + */ public String getAsText() { try @@ -45,9 +49,11 @@ public class ReferencedEntryEditor extends PropertyEditorSupport } } - /** Sets the value of the editor by performing a lookup and mapping the result + /** + * Sets the value of the editor by performing a lookup and mapping the result * to the target type using an object directory mapper. - * @param text The distinguished name of an ldap entry. + * + * @param text The distinguished name of an ldap entry. * @throws IllegalArgumentException */ public void setAsText(String text) throws IllegalArgumentException @@ -60,6 +66,15 @@ public class ReferencedEntryEditor extends PropertyEditorSupport dn.removeFirst(); } } - setValue(ldapTemplate.lookup(dn, objectDirectoryMapper)); + try + { + setValue(ldapTemplate.lookup(dn, objectDirectoryMapper)); + } + catch (NameNotFoundException e) + { + setValue(null); + + } + } }