Mongo db entity relationship implementation using Spring data











up vote
0
down vote

favorite












I am learning Spring with Mongo DB and I'm feeling difficulty in learning the entity-relationship model.
Can anyone teach me how can I implement the following design?



Person collection
A person class




  • id

  • name

  • List of the sports object


Sport collection
A Sport class




  • id (Auto-generated)

  • sport name


while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.



While I am retrieving Person class, associated sports class should be fetched from the corresponding collection.
I have tried with @DBRef and it is not worked for me.
It will be very helpful if anyone teaches me this scenario or giving the reference to learning this concept.



Very thanks in advance.










share|improve this question









New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • try this link: stackoverflow.com/questions/10148308/…)
    – Alok Deshwal
    Nov 4 at 12:48

















up vote
0
down vote

favorite












I am learning Spring with Mongo DB and I'm feeling difficulty in learning the entity-relationship model.
Can anyone teach me how can I implement the following design?



Person collection
A person class




  • id

  • name

  • List of the sports object


Sport collection
A Sport class




  • id (Auto-generated)

  • sport name


while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.



While I am retrieving Person class, associated sports class should be fetched from the corresponding collection.
I have tried with @DBRef and it is not worked for me.
It will be very helpful if anyone teaches me this scenario or giving the reference to learning this concept.



Very thanks in advance.










share|improve this question









New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • try this link: stackoverflow.com/questions/10148308/…)
    – Alok Deshwal
    Nov 4 at 12:48















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am learning Spring with Mongo DB and I'm feeling difficulty in learning the entity-relationship model.
Can anyone teach me how can I implement the following design?



Person collection
A person class




  • id

  • name

  • List of the sports object


Sport collection
A Sport class




  • id (Auto-generated)

  • sport name


while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.



While I am retrieving Person class, associated sports class should be fetched from the corresponding collection.
I have tried with @DBRef and it is not worked for me.
It will be very helpful if anyone teaches me this scenario or giving the reference to learning this concept.



Very thanks in advance.










share|improve this question









New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I am learning Spring with Mongo DB and I'm feeling difficulty in learning the entity-relationship model.
Can anyone teach me how can I implement the following design?



Person collection
A person class




  • id

  • name

  • List of the sports object


Sport collection
A Sport class




  • id (Auto-generated)

  • sport name


while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.



While I am retrieving Person class, associated sports class should be fetched from the corresponding collection.
I have tried with @DBRef and it is not worked for me.
It will be very helpful if anyone teaches me this scenario or giving the reference to learning this concept.



Very thanks in advance.







spring mongodb spring-mvc entity-relationship spring-data-mongodb






share|improve this question









New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 4 at 15:36









cogent

315112




315112






New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 4 at 10:11









Raghu

32




32




New contributor




Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Raghu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • try this link: stackoverflow.com/questions/10148308/…)
    – Alok Deshwal
    Nov 4 at 12:48




















  • try this link: stackoverflow.com/questions/10148308/…)
    – Alok Deshwal
    Nov 4 at 12:48


















try this link: stackoverflow.com/questions/10148308/…)
– Alok Deshwal
Nov 4 at 12:48






try this link: stackoverflow.com/questions/10148308/…)
– Alok Deshwal
Nov 4 at 12:48














1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted











while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.




In Spring-data-mongo cascade save not supported. Therefore referencing object will not be saved to the database automatically. To achieve the same you have two option.

1) First, save sports collection (if that record not found in the collection) then save the reference of sports to person collection.

2) Make you custom cascade save implementation. For reference see this.






share|improve this answer





















  • Kindly share any reference if you have for doing "save the reference of sports to person collection."
    – Raghu
    Nov 4 at 14:11












  • Reference is already given at the end of answer.
    – cogent
    Nov 4 at 14:25











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
});


}
});






Raghu is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139677%2fmongo-db-entity-relationship-implementation-using-spring-data%23new-answer', 'question_page');
}
);

Post as a guest
































1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted











while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.




In Spring-data-mongo cascade save not supported. Therefore referencing object will not be saved to the database automatically. To achieve the same you have two option.

1) First, save sports collection (if that record not found in the collection) then save the reference of sports to person collection.

2) Make you custom cascade save implementation. For reference see this.






share|improve this answer





















  • Kindly share any reference if you have for doing "save the reference of sports to person collection."
    – Raghu
    Nov 4 at 14:11












  • Reference is already given at the end of answer.
    – cogent
    Nov 4 at 14:25















up vote
0
down vote



accepted











while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.




In Spring-data-mongo cascade save not supported. Therefore referencing object will not be saved to the database automatically. To achieve the same you have two option.

1) First, save sports collection (if that record not found in the collection) then save the reference of sports to person collection.

2) Make you custom cascade save implementation. For reference see this.






share|improve this answer





















  • Kindly share any reference if you have for doing "save the reference of sports to person collection."
    – Raghu
    Nov 4 at 14:11












  • Reference is already given at the end of answer.
    – cogent
    Nov 4 at 14:25













up vote
0
down vote



accepted







up vote
0
down vote



accepted







while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.




In Spring-data-mongo cascade save not supported. Therefore referencing object will not be saved to the database automatically. To achieve the same you have two option.

1) First, save sports collection (if that record not found in the collection) then save the reference of sports to person collection.

2) Make you custom cascade save implementation. For reference see this.






share|improve this answer













while I am saving the person class which contains sports class, Sports entity should be saved in Sports collection if it is not already present and Person entity should be stored in Person collection with Sports objects Reference.




In Spring-data-mongo cascade save not supported. Therefore referencing object will not be saved to the database automatically. To achieve the same you have two option.

1) First, save sports collection (if that record not found in the collection) then save the reference of sports to person collection.

2) Make you custom cascade save implementation. For reference see this.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 4 at 10:40









cogent

315112




315112












  • Kindly share any reference if you have for doing "save the reference of sports to person collection."
    – Raghu
    Nov 4 at 14:11












  • Reference is already given at the end of answer.
    – cogent
    Nov 4 at 14:25


















  • Kindly share any reference if you have for doing "save the reference of sports to person collection."
    – Raghu
    Nov 4 at 14:11












  • Reference is already given at the end of answer.
    – cogent
    Nov 4 at 14:25
















Kindly share any reference if you have for doing "save the reference of sports to person collection."
– Raghu
Nov 4 at 14:11






Kindly share any reference if you have for doing "save the reference of sports to person collection."
– Raghu
Nov 4 at 14:11














Reference is already given at the end of answer.
– cogent
Nov 4 at 14:25




Reference is already given at the end of answer.
– cogent
Nov 4 at 14:25










Raghu is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















Raghu is a new contributor. Be nice, and check out our Code of Conduct.













Raghu is a new contributor. Be nice, and check out our Code of Conduct.












Raghu is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139677%2fmongo-db-entity-relationship-implementation-using-spring-data%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini