Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Video.java and VideoRepository to use String for Id. #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rbramwell
Copy link

'Id' needs to be String in order for Spring Data JPA to correctly assign an allow MongoDB to automatically generate an ObjectId('...') and return to Spring Data JPA.

MongoDB's auto generated ObjectId consists of alphanumeric characters and hyphens '-'. When a long is used as the datatype for the Id, Spring Data MongoDB will issue an update/overwrite a single document in MongoDB with '_Id': NumberLong(0).

Output from mongo shell (Id as long):

db.video.find().pretty()
{
"_id" : NumberLong(0),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"url" : "http://coursera.org/some/video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"duration" : NumberLong(2880000)
}
This differs from the desired outcome which is to create a new (additional) document on subsequent calls to src / test / java / org / magnum / mobilecloud / integration / test / VideoSvcClientApiTest.java

Output from mongo shell (Id as String in 2nd document):

db.video.find().pretty()
{
"_id" : NumberLong(0),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"url" : "http://coursera.org/some/video-3a3b3158-9517-48c4-bdbd-718374e296bd",
"duration" : NumberLong(2880000)
}
{
"_id" : ObjectId("545cba6444ae69b880ba589b"),
"_class" : "org.magnum.mobilecloud.video.repository.Video",
"name" : "Video-a820232d-dca3-4754-8962-f5355e408d61",
"url" : "http://coursera.org/some/video-a820232d-dca3-4754-8962-f5355e408d61",
"duration" : NumberLong(60000)
}
Updated VideoRepository.java to extend MongoRepository<Video, String> instead of MongoRepository<Video, Long>. This is in line with change to Id as String insteaf og long.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant