My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for

UsingCollections  
Using Lists, Sets, and Maps.
Updated Dec 6, 2010 by scotthernandez

Using Collections

Morphia supports collections (List, Set, Map) and arrays (Integer).

...

private Set<String> tags;

private Map<String,Translation> translations;

@Reference
private List<Article> relatedArticles;
...

Morphia will use the following implementations (by default) when creating collections:

  • java.util.ArrayList for List
  • java.util.HashSet for Set
  • java.util.HashMap for Map

If you want to use another implementation, you can override this on the annotations:

...
@Property(concreteClass = java.util.TreeSet.class)
private Set<String> tags;

@Embedded(concreteClass = java.util.TreeMap.class)
private Map<String,Translation> translations;

@Reference(concreteClass = java.util.Vector.class)
private List<Article> relatedArticles;
...

Sign in to add a comment
Powered by Google Project Hosting