Morphia Question

43 views
Skip to first unread message

GonzalesDK

unread,
Oct 5, 2011, 8:04:26 AM10/5/11
to play-framework
Hi there.
I have a News.java domain object, it's very simple for now
@Entity
public class News extends Model {
public String title;
public String text;
public String intro;
public Blob newsImage;
//there are more contructors
public News() {
}

public void addImage(File image, String imageType) {

Blob photo = new Blob(image,imageType);
}
********
Test
News news = new News();
news.intro="Bla";
news.text="Hello";
news.title="World";
File test = new File("somepath\\test.jpg");
String iType="image/jpeg";
news.addImage(test,iType);
news.save();
assertNotNull(news);
assertNotNull(news.photo);

This works as expected

What I would like to do is however add a list of images.
@Entity
public class News extends Model {
public String title;
public String text;
public String intro;

public List<Blob> photos ;
public News() {
this.photos = new ArrayList<Blob>();
}

public void addImage(File image, String imageType) {

Blob photo = new Blob(image,imageType);
photos.add(photo);

}

This however to my surprise does not work
Oops: RuntimeException
An unexpected error occured caused by exception RuntimeException:
bad type, not parameterized..
Oops: RuntimeException
An unexpected error occured caused by exception RuntimeException: bad
type, not
parameterized...

play.exceptions.UnexpectedException: Unexpected Error
at play.Play.start(Play.java:525)
at play.Play.detectChanges(Play.java:610)
at play.Invoker$Invocation.init(Invoker.java:186)
at Invocation.HTTP Request(Play!)
Caused by: java.lang.RuntimeException: bad type, not parameterized...
at
com.google.code.morphia.utils.ReflectionUtils.isPropertyType(Reflecti
onUtils.java:194)
at
com.google.code.morphia.mapping.MappedField.discover(MappedField.java
:102)
at
com.google.code.morphia.mapping.MappedField.<init>(MappedField.java:7
8)
at
com.google.code.morphia.mapping.MappedClass.discover(MappedClass.java
:166)
at
com.google.code.morphia.mapping.MappedClass.<init>(MappedClass.java:1
10)
at
com.google.code.morphia.mapping.Mapper.getMappedClass(Mapper.java:200
)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:319)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:280)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:341)
at
com.google.code.morphia.DatastoreImpl.ensureIndexes(DatastoreImpl.jav
a:334)
at
play.modules.morphia.MorphiaPlugin.configureDs_(MorphiaPlugin.java:31
5)
at
play.modules.morphia.MorphiaPlugin.onApplicationStart(MorphiaPlugin.j
ava:258)
at
play.plugins.PluginCollection.onApplicationStart(PluginCollection.jav
a:425)
at play.Play.start(Play.java:495)
... 3 more



*****************
Could anyone point me in the right direction? I would just simply like
to add an arbitary amount of images to a news object.
Thx





Alexander Reelsen

unread,
Oct 5, 2011, 4:37:40 PM10/5/11
to play-fr...@googlegroups.com
Hi

GonzalesDK wrote:
> What I would like to do is however add a list of images.
> @Entity
> public class News extends Model {
> public String title;
> public String text;
> public String intro;
>
> public List<Blob> photos ;
> public News() {
> this.photos = new ArrayList<Blob>();
> }
>
> public void addImage(File image, String imageType) {
>
> Blob photo = new Blob(image,imageType);
> photos.add(photo);
>
> }
>
> This however to my surprise does not work
> Oops: RuntimeException
> An unexpected error occured caused by exception RuntimeException:
> bad type, not parameterized..
> Oops: RuntimeException
> An unexpected error occured caused by exception RuntimeException: bad
> type, not
> parameterized...

This is true. Lists of Blobs are not supported currently. With the
current type of implementation it is not too easy to implement I guess.
Need to investigate this, but currently I do not have time, sorry.


--Alexander

Reply all
Reply to author
Forward
0 new messages