-
May 27th, 2012, 10:01 AM
#1
Inserting Embedded document data
I am new to spring-data and just trying to understand the best way to get things done. Assume I have a collection called Artist, and with in I have a list of Albums, something like this:
@Document
public class Artist {
@Id
String artistId;
String name;
List<Album> albums;
}
if I want to add an album to this artist what is the best way to do this? Should I first find the artist, add to the list and then save the artist?
Artist a=artistRepo.findByName("thename");
a.getAlbums().add(new Album());
artistRepo.save(a);
or is there a more efficient way to do this?
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules