Skip to content

Commit a786687

Browse files
committed
Clarify that index has precedence
Closes gh-940
1 parent 3d929dd commit a786687

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/docs/asciidoc/index.adoc

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,10 +1091,69 @@ The `@Attribute` annotation is used to map object class fields to entity fields.
10911091

10921092
The `@DnAttribute` annotation is used to map object class fields to and from components in the distinguished name of an entry.
10931093
Fields annotated with `@DnAttribute` are automatically populated with the appropriate value from the distinguished name when an entry is read from the directory tree.
1094+
1095+
Consider a class with the following annotation:
1096+
1097+
[tabs]
1098+
======
1099+
Java::
1100+
+
1101+
[source,java,role="primary"]
1102+
----
1103+
@DnAttribute(name="uid")
1104+
String uid;
1105+
----
1106+
=====
1107+
1108+
and a DN like the following:
1109+
1110+
====
1111+
[source,bash]
1112+
----
1113+
uid=carla,dc=springframework,dc=org
1114+
----
1115+
====
1116+
1117+
Then Spring LDAP will populate `uid` using `uid=carla` instead of looking for a `uid` attribute.
1118+
1119+
[NOTE]
1120+
----
10941121
Only fields of type `String` can be annotated with `@DnAttribute`. Other types are not supported.
1095-
If the `index` attribute of all `@DnAttribute` annotations in a class is specified, the DN can also be automatically calculated when creating and updating entries.
1122+
----
1123+
1124+
You can alternatively supply an index like so:
1125+
1126+
[tabs]
1127+
======
1128+
Java::
1129+
+
1130+
[source,java,role="primary"]
1131+
----
1132+
@DnAttribute(index=1)
1133+
String uid;
1134+
1135+
@DnAttribute(index=0)
1136+
String department;
1137+
----
1138+
=====
1139+
1140+
which is handy for DNs that have multiple components:
1141+
1142+
====
1143+
[source,bash]
1144+
----
1145+
uid=carla,department=engineering,dc=springframework,dc=org
1146+
----
1147+
====
1148+
1149+
Using an `index` also allows Spring LDAP to compute the DN for you when creating or locating an entity for update or deletion.
10961150
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.
10971151

1152+
[NOTE]
1153+
----
1154+
Note that while both attributes are present on `@DnAttribute`, if `index` is specified, then `name` is ignored.
1155+
----
1156+
10981157
The `@Transient` annotation indicates that the field should be ignored by the object directory mapping and not mapped to an underlying LDAP property. Note that if a `@DnAttribute` is not to be bound to an `Attribute`. That is, it is only part of the Distinguished Name and not represented by an object attribute. It must also be annotated with `@Transient`.
10991158

11001159
=== Execution

0 commit comments

Comments
 (0)