You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/ROOT/pages/odm.adoc
+53-2
Original file line number
Diff line number
Diff line change
@@ -48,12 +48,63 @@ Finally, `@Attribute` also provides the type declaration, which lets you indicat
48
48
Third, the `@Transient` annotation indicates that the given entity field does not map to an LDAP attribute.
49
49
50
50
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
+
----
51
75
Only fields of type `String` can be annotated with `@DnAttribute`. Other types are not supported.
76
+
----
52
77
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:
Using an `index` also allows Spring LDAP to compute the DN for you when creating or locating an entity for update or deletion.
55
101
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.
56
102
103
+
[NOTE]
104
+
----
105
+
Note that while both attributes are present on `@DnAttribute`, if `index` is specified, then `name` is ignored.
106
+
----
107
+
57
108
[NOTE]
58
109
Remember that all fields are mapped to LDAP attributes by default.
59
110
`@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