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?










share|improve this question


























    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?










    share|improve this question
























      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 at 11:02









      Peter

      111215




      111215
























          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.






          share|improve this answer

















          • 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




















          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": ".."}.







          share|improve this answer





















          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          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

























          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.






          share|improve this answer

















          • 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

















          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.






          share|improve this answer

















          • 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















          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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
















          • 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














          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": ".."}.







          share|improve this answer





















          • 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















          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": ".."}.







          share|improve this answer





















          • 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













          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": ".."}.







          share|improve this answer












          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": ".."}.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          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


















          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Can I use Tabulator js library in my java Spring + Thymeleaf project?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents