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.
spring mongodb spring-mvc entity-relationship spring-data-mongodb
New contributor
add a comment |
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.
spring mongodb spring-mvc entity-relationship spring-data-mongodb
New contributor
try this link: stackoverflow.com/questions/10148308/…)
– Alok Deshwal
Nov 4 at 12:48
add a comment |
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.
spring mongodb spring-mvc entity-relationship spring-data-mongodb
New contributor
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
spring mongodb spring-mvc entity-relationship spring-data-mongodb
New contributor
New contributor
edited Nov 4 at 15:36
cogent
315112
315112
New contributor
asked Nov 4 at 10:11
Raghu
32
32
New contributor
New contributor
try this link: stackoverflow.com/questions/10148308/…)
– Alok Deshwal
Nov 4 at 12:48
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Raghu is a new contributor. Be nice, and check out our Code of Conduct.
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
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
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
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
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
try this link: stackoverflow.com/questions/10148308/…)
– Alok Deshwal
Nov 4 at 12:48