DATACOUCH-518 - Update documentation on entities.

This commit is contained in:
Michael Nitschinger
2020-04-14 08:55:44 +02:00
parent 77fef2ebea
commit 5d666cc7ee
2 changed files with 21 additions and 10 deletions

View File

@@ -8,16 +8,14 @@ include::{spring-data-commons-docs}/object-mapping.adoc[leveloffset=+1]
[[basics]]
== Documents and Fields
All entities should be annotated with the `@Document` annotation.
All entities should be annotated with the `@Document` annotation, but it is not a requirement.
Also, every field in the entity should be annotated with the `@Field` annotation from the Couchbase SDK. While this is - strictly speaking - optional, it helps to reduce edge cases and clearly shows the intent and design of the entity.
It can also be used to store the field under a different name.
Also, every field in the entity should be annotated with the `@Field` annotation. While this is - strictly speaking -
optional, it helps to reduce edge cases and clearly shows the intent and design of the entity. It can also be used to
store the field under a different name.
There is also a special `@Id` annotation which needs to be always in place.
Best practice is to also name the property `id`.
TIP: Both the Couchbase SDK and Spring Data define their own `@Id` annotation.
Either can be used (the Spring Data one will get priority if both are found on different fields).
There is also a special `@Id` annotation which needs to be always in place. Best practice is to also name the property
`id`.
Here is a very simple `User` entity:
@@ -25,8 +23,8 @@ Here is a very simple `User` entity:
====
[source,java]
----
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document

View File

@@ -18,6 +18,19 @@ The new SDK still has an environment that is used to configure it, so you can ov
For more information, see <<couchbase.configuration>>.
[[couchbase.migrating.entities]]
== Entities
How to deal with entities has not changed, although since the SDK now does not ship annotations anymore only Spring-Data related annotations are supported.
Specifically:
- `com.couchbase.client.java.repository.annotation.Id` became `import org.springframework.data.annotation.Id`
- `com.couchbase.client.java.repository.annotation.Field` became `import org.springframework.data.couchbase.core.mapping.Field`
The `org.springframework.data.couchbase.core.mapping.Document` annotation stayed the same.
For more information, see <<couchbase.entity>>.
[[couchbase.migrating.template]]
== Template and ReactiveTemplate