Skip to content

Commit 73641fd

Browse files
orange-guomp911de
authored andcommitted
Fix projection query field mapping issue.
When using projection queries with entities that have @Attribute annotations for LDAP field mapping, the query was using Java field names instead of the mapped LDAP attribute names. This caused queries to fail when the Java field name differs from the LDAP attribute name. Signed-off-by: Xiangcheng Kuo <[email protected]> Closes #573
1 parent 41ff966 commit 73641fd

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/main/java/org/springframework/data/ldap/repository/query/LdapQueryCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
*
4040
* @author Mattias Hellborg Arthursson
4141
* @author Mark Paluch
42+
* @author Xiangcheng Kuo
4243
*/
4344
class LdapQueryCreator extends AbstractQueryCreator<LdapQuery, ContainerCriteria> {
4445

@@ -80,7 +81,7 @@ protected ContainerCriteria create(Part part, Iterator<Object> iterator) {
8081
}
8182

8283
if (!inputProperties.isEmpty()) {
83-
query.attributes(inputProperties.toArray(new String[0]));
84+
query.attributes(inputProperties.stream().map(prop -> mapper.attributeFor(entityType, prop)).toList().toArray(new String[0]));
8485
}
8586

8687
ConditionCriteria criteria = query.where(getAttribute(part));

src/test/java/org/springframework/data/ldap/repository/LdapRepositoryUnitTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void shouldReturnInterfaceProjection() {
7878
verify(ldapOperations).findOne(captor.capture(), any());
7979

8080
LdapQuery query = captor.getValue();
81-
assertThat(query.attributes()).containsOnly("lastName");
81+
assertThat(query.attributes()).containsOnly("sn");
8282
}
8383

8484
@Test
@@ -96,7 +96,7 @@ void shouldReturnDynamicDtoProjection() {
9696
verify(ldapOperations).findOne(captor.capture(), any());
9797

9898
LdapQuery query = captor.getValue();
99-
assertThat(query.attributes()).contains("lastName");
99+
assertThat(query.attributes()).contains("sn");
100100
}
101101

102102
@Test
@@ -115,7 +115,7 @@ void shouldReturnInterfaceProjectionAsStream() {
115115
verify(ldapOperations).find(captor.capture(), any());
116116

117117
LdapQuery query = captor.getValue();
118-
assertThat(query.attributes()).containsOnly("lastName");
118+
assertThat(query.attributes()).containsOnly("sn");
119119
}
120120

121121
interface PersonRepository extends LdapRepository<UnitTestPerson> {

0 commit comments

Comments
 (0)