Skip to content

Commit 847b9ac

Browse files
committed
Clarify that index has precedence
Closes gh-940
1 parent 4733b6c commit 847b9ac

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

Diff for: modules/ROOT/pages/odm.adoc

+53-2
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,63 @@ Finally, `@Attribute` also provides the type declaration, which lets you indicat
4848
Third, the `@Transient` annotation indicates that the given entity field does not map to an LDAP attribute.
4949

5050
Finally, the `@DnAttribute` annotation additionally maps entity fields to components of an entry's distinguished name.
51+
52+
Consider a class with the following annotation:
53+
54+
====
55+
[source,java,role="primary"]
56+
----
57+
@DnAttribute(name="uid")
58+
String uid;
59+
----
60+
====
61+
62+
and a DN like the following:
63+
64+
====
65+
[source,bash]
66+
----
67+
uid=carla,dc=springframework,dc=org
68+
----
69+
====
70+
71+
Then Spring LDAP will populate `uid` using `uid=carla` instead of looking for a `uid` attribute.
72+
73+
[NOTE]
74+
----
5175
Only fields of type `String` can be annotated with `@DnAttribute`. Other types are not supported.
76+
----
5277

53-
[TIP]
54-
When the `index` attribute of all `@DnAttribute` annotations in a class is specified, the DN can also be automatically calculated when creating and updating entries.
78+
You can alternatively supply an index like so:
79+
80+
====
81+
[source,java,role="primary"]
82+
----
83+
@DnAttribute(index=1)
84+
String uid;
85+
86+
@DnAttribute(index=0)
87+
String department;
88+
----
89+
====
90+
91+
which is handy for DNs that have multiple components:
92+
93+
====
94+
[source,bash]
95+
----
96+
uid=carla,department=engineering,dc=springframework,dc=org
97+
----
98+
====
99+
100+
Using an `index` also allows Spring LDAP to compute the DN for you when creating or locating an entity for update or deletion.
55101
For update scenarios, this also automatically takes care of moving entries in the tree if attributes that are part of the distinguished name have changed.
56102

103+
[NOTE]
104+
----
105+
Note that while both attributes are present on `@DnAttribute`, if `index` is specified, then `name` is ignored.
106+
----
107+
57108
[NOTE]
58109
Remember that all fields are mapped to LDAP attributes by default.
59110
`@DnAttribute` does not change this; in other words, fields annotated with `@DnAttribute` will also map to an LDAP attribute, unless you also annotate the field with `@Transient`.

0 commit comments

Comments
 (0)