Skip to content

Commit 18a0d5a

Browse files
committed
docs: include documentation about Id annotation at ARangoDB
Signed-off-by: Otavio Santana <otaviopolianasantana@gmail.com>
1 parent b7cdbdd commit 18a0d5a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

README.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,29 @@ private ArangoDBTemplate template;
163163
List<Person> people = template.aql("FOR p IN Person FILTER p.name = @name RETURN p", params);
164164
----
165165

166+
=== How @Id Works in ArangoDB
167+
168+
In ArangoDB, the `_id` field is a read-only, auto-generated value created by the database. It is a combination of the collection name and the `_key` field in the format `<collection-name>/<_key>`. The `_id` is automatically managed by the database, meaning any value set by the client will be ignored.
169+
170+
To map the `_id` and `_key` fields in your entities, you can use the `@Id` annotation and specify the `_key` field explicitly. This allows you to manage the `_key` value directly in your code while letting the database handle the `_id` generation.
171+
172+
For example:
173+
174+
[source,java]
175+
----
176+
@Entity
177+
public class User {
178+
179+
@Id("_key")
180+
private String key;
181+
182+
private String name;
183+
184+
}
185+
----
186+
187+
In this example, the `_key` field is annotated with `@Id("_key")`, allowing the application to control the `_key` value while the database auto-generates the corresponding `_id` field. This approach is useful for scenarios where you need to set or manage the `_key` value explicitly in your application logic.
188+
166189

167190
== Cassandra
168191

0 commit comments

Comments
 (0)