How to tell Spring Data Couchbase to embed or reference entity?
up vote
2
down vote
favorite
My question is simple: how do I tell Spring Data Couchbase to either embed or reference an entity using @Field? Is there an extra annotation to it?
spring-data couchbase spring-data-couchbase
add a comment |
up vote
2
down vote
favorite
My question is simple: how do I tell Spring Data Couchbase to either embed or reference an entity using @Field? Is there an extra annotation to it?
spring-data couchbase spring-data-couchbase
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
My question is simple: how do I tell Spring Data Couchbase to either embed or reference an entity using @Field? Is there an extra annotation to it?
spring-data couchbase spring-data-couchbase
My question is simple: how do I tell Spring Data Couchbase to either embed or reference an entity using @Field? Is there an extra annotation to it?
spring-data couchbase spring-data-couchbase
spring-data couchbase spring-data-couchbase
asked Nov 15 at 11:02
Peter
111215
111215
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.
Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.
Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.
My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
add a comment |
up vote
1
down vote
Not sure about which extra annotation you're asking for.
According to the documentation:
All entities should be annotated with the
@Document
annotation.
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.
There is also a special
@Id
annotation which needs to be always in
place. Best practice is to also name the property id.
For example:
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class User {
@Id
private String id;
@Field
private String firstname;
@Field
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}
Being said this, there is another annotation in the documentation that may be helpful:
If you want a different representation of the field name inside the
document in contrast to the field name used in your entity, you can
set a different name on the@Field
annotation. For example if you
want to keep your documents small you can set the firstname field to
@Field("fname")
. In the JSON document, you’ll see{"fname": ".."}
instead of{"firstname": ".."}
.
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.
Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.
Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.
My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
add a comment |
up vote
1
down vote
accepted
You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.
Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.
Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.
My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.
Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.
Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.
My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.
You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.
Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.
Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.
My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.
answered Nov 15 at 21:08
deniswsrosa
522414
522414
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
add a comment |
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
1
1
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
Thank you for the clarification! This article made me think it's possible btw: blog.couchbase.com/data-modelling-when-embed-or-refer
– Peter
Nov 16 at 6:31
add a comment |
up vote
1
down vote
Not sure about which extra annotation you're asking for.
According to the documentation:
All entities should be annotated with the
@Document
annotation.
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.
There is also a special
@Id
annotation which needs to be always in
place. Best practice is to also name the property id.
For example:
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class User {
@Id
private String id;
@Field
private String firstname;
@Field
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}
Being said this, there is another annotation in the documentation that may be helpful:
If you want a different representation of the field name inside the
document in contrast to the field name used in your entity, you can
set a different name on the@Field
annotation. For example if you
want to keep your documents small you can set the firstname field to
@Field("fname")
. In the JSON document, you’ll see{"fname": ".."}
instead of{"firstname": ".."}
.
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
add a comment |
up vote
1
down vote
Not sure about which extra annotation you're asking for.
According to the documentation:
All entities should be annotated with the
@Document
annotation.
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.
There is also a special
@Id
annotation which needs to be always in
place. Best practice is to also name the property id.
For example:
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class User {
@Id
private String id;
@Field
private String firstname;
@Field
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}
Being said this, there is another annotation in the documentation that may be helpful:
If you want a different representation of the field name inside the
document in contrast to the field name used in your entity, you can
set a different name on the@Field
annotation. For example if you
want to keep your documents small you can set the firstname field to
@Field("fname")
. In the JSON document, you’ll see{"fname": ".."}
instead of{"firstname": ".."}
.
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
add a comment |
up vote
1
down vote
up vote
1
down vote
Not sure about which extra annotation you're asking for.
According to the documentation:
All entities should be annotated with the
@Document
annotation.
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.
There is also a special
@Id
annotation which needs to be always in
place. Best practice is to also name the property id.
For example:
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class User {
@Id
private String id;
@Field
private String firstname;
@Field
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}
Being said this, there is another annotation in the documentation that may be helpful:
If you want a different representation of the field name inside the
document in contrast to the field name used in your entity, you can
set a different name on the@Field
annotation. For example if you
want to keep your documents small you can set the firstname field to
@Field("fname")
. In the JSON document, you’ll see{"fname": ".."}
instead of{"firstname": ".."}
.
Not sure about which extra annotation you're asking for.
According to the documentation:
All entities should be annotated with the
@Document
annotation.
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.
There is also a special
@Id
annotation which needs to be always in
place. Best practice is to also name the property id.
For example:
import com.couchbase.client.java.repository.annotation.Id;
import com.couchbase.client.java.repository.annotation.Field;
import org.springframework.data.couchbase.core.mapping.Document;
@Document
public class User {
@Id
private String id;
@Field
private String firstname;
@Field
private String lastname;
public User(String id, String firstname, String lastname) {
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
}
public String getId() {
return id;
}
public String getFirstname() {
return firstname;
}
public String getLastname() {
return lastname;
}
}
Being said this, there is another annotation in the documentation that may be helpful:
If you want a different representation of the field name inside the
document in contrast to the field name used in your entity, you can
set a different name on the@Field
annotation. For example if you
want to keep your documents small you can set the firstname field to
@Field("fname")
. In the JSON document, you’ll see{"fname": ".."}
instead of{"firstname": ".."}
.
answered Nov 15 at 12:08
juanlumn
1,3991119
1,3991119
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
add a comment |
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
Since Field doesn't have any parameter like StoreMode.REFERENCE or StoreMode.EMBEDDED I tought there is an extra annotation to indicate. What decides which storage mode is used then? I'm looking for something like DbRef in Mongo.
– Peter
Nov 15 at 14:00
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
I see, something similar to this SO post? I have not found anything similar in the Spring Data Documentation.
– juanlumn
Nov 15 at 14:36
1
1
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
Yeah, something like that. Unfortunately me neither, but it would be quite a basic function...
– Peter
Nov 15 at 16:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318011%2fhow-to-tell-spring-data-couchbase-to-embed-or-reference-entity%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown