Skip to content

Instantly share code, notes, and snippets.

@greenlaw110
Created June 18, 2012 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenlaw110/2947784 to your computer and use it in GitHub Desktop.
Save greenlaw110/2947784 to your computer and use it in GitHub Desktop.
How to create a play-morphia model which contains multiple gridfs blobs
package models;
import com.google.code.morphia.annotations.Entity;
import play.modules.morphia.Model;
import java.util.List;
/**
* An album could store multiple photos persistent in the gridfs
*/
@Entity(value = "album", noClassnameStored = true)
public class Album extends Model {
...
@Reference
public List<Asset> photos;
@Reference
public Asset frontImage;
@Reference
public Asset thumbnail;
...
}
package models;
import com.google.code.morphia.annotations.Entity;
import play.data.validation.MaxSize;
import play.modules.morphia.Blob;
import play.modules.morphia.Model;
import javax.activation.MimetypesFileTypeMap;
import java.io.File;
/**
* Store blob type assets, e.g. images, videos etc
*/
@Entity(value = "asset", noClassnameStored = true)
public class Asset extends Model {
public Blob content;
@MaxSize(10000)
public String description;
public Asset(File file) {
content = new Blob(file);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment