BlackLabs / play-morphia

Provide mongodb access service to play.db.Model via Morphia
Apache License 2.0
130 stars 51 forks source link

"Multiple embedded objects not supported yet"? #28

Open yuyou opened 13 years ago

yuyou commented 13 years ago

I saw following line in Model source code: Logger.debug("multiple embedded objects not supported yet");

Could you plz elaborate it more? what does it exactly imply to the model design?

Thanks.

BRs,

Yu

greenlaw110 commented 13 years ago

That only impact the case when you want to use Model.edit() method, e.g. load yml data file or edit current object using params coming from http form. You can still construct a complicated model structure if you use APIs.

chrislambert commented 12 years ago

This is something we need badly. We're not able to load MorphiaFixtures that contain lists of embedded documents, which happens in almost every one of our collections.

We may try to fix it this week if you think it's something simple. Right now, our workaround is to instantiate a bunch of embedded documents programmatically within setUp(). It's pretty ugly.

greenlaw110 commented 12 years ago

Does JPA embedded object list supported now?

chrislambert commented 12 years ago

Looks like it does in 1.2.4: https://play.lighthouseapp.com/projects/57987/tickets/74-fixtures-should-support-assigning-an-embedded-object

bolinfest commented 12 years ago

Unfortunately, I do not believe this is the case. I have been playing with the code tonight, and I put together a pull request for Play that I believe is required to support lists of @Embedded objects in PlayMorphia fixtures:

https://github.com/playframework/play/pull/433

Green, if you could provide any insight on this, it would be a big help. With this change, I end up with instances of the @Embedded type in the List, but none of the List's elements have its fields initialized (though this is better than the NullPointerExceptions that were thrown previously). Admittedly, much of the relevant classes that affect how fixtures are instantiated (EmbeddedMapper, Mapper) are in Morphia rather than PlayMorphia, but I'm guessing you are more familiar with them than I am.

On Mon, Jan 9, 2012 at 9:48 PM, chrislambert < reply@reply.github.com

wrote:

Looks like it does in 1.2.4:

https://play.lighthouseapp.com/projects/57987/tickets/74-fixtures-should-support-assigning-an-embedded-object


Reply to this email directly or view it on GitHub: https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3425646

greenlaw110 commented 12 years ago

It's admitted that binding refactory work is not mature in play 1.2.4, and Morphia is not be able to work well with this version. let's wait for 1.2.5 release and I will look back this issue then

On Tue, Jan 10, 2012 at 9:57 PM, bolinfest < reply@reply.github.com

wrote:

Unfortunately, I do not believe this is the case. I have been playing with the code tonight, and I put together a pull request for Play that I believe is required to support lists of @Embedded objects in PlayMorphia fixtures:

https://github.com/playframework/play/pull/433

Green, if you could provide any insight on this, it would be a big help. With this change, I end up with instances of the @Embedded type in the List, but none of the List's elements have its fields initialized (though this is better than the NullPointerExceptions that were thrown previously). Admittedly, much of the relevant classes that affect how fixtures are instantiated (EmbeddedMapper, Mapper) are in Morphia rather than PlayMorphia, but I'm guessing you are more familiar with them than I am.

On Mon, Jan 9, 2012 at 9:48 PM, chrislambert < reply@reply.github.com

wrote:

Looks like it does in 1.2.4:

https://play.lighthouseapp.com/projects/57987/tickets/74-fixtures-should-support-assigning-an-embedded-object


Reply to this email directly or view it on GitHub:

https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3425646


Reply to this email directly or view it on GitHub: https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3428147

bolinfest commented 12 years ago

Well, unfortunately, we really need this functionality now, so I guess we'll have to keep hacking the source ourselves :(

On Tue, Jan 10, 2012 at 4:15 AM, Green Luo < reply@reply.github.com

wrote:

It's admitted that binding refactory work is not mature in play 1.2.4, and Morphia is not be able to work well with this version. let's wait for 1.2.5 release and I will look back this issue then

On Tue, Jan 10, 2012 at 9:57 PM, bolinfest < reply@reply.github.com

wrote:

Unfortunately, I do not believe this is the case. I have been playing with the code tonight, and I put together a pull request for Play that I believe is required to support lists of @Embedded objects in PlayMorphia fixtures:

https://github.com/playframework/play/pull/433

Green, if you could provide any insight on this, it would be a big help. With this change, I end up with instances of the @Embedded type in the List, but none of the List's elements have its fields initialized (though this is better than the NullPointerExceptions that were thrown previously). Admittedly, much of the relevant classes that affect how fixtures are instantiated (EmbeddedMapper, Mapper) are in Morphia rather than PlayMorphia, but I'm guessing you are more familiar with them than I am.

On Mon, Jan 9, 2012 at 9:48 PM, chrislambert < reply@reply.github.com

wrote:

Looks like it does in 1.2.4:

https://play.lighthouseapp.com/projects/57987/tickets/74-fixtures-should-support-assigning-an-embedded-object


Reply to this email directly or view it on GitHub:

https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3425646


Reply to this email directly or view it on GitHub:

https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3428147


Reply to this email directly or view it on GitHub: https://github.com/greenlaw110/play-morphia/issues/28#issuecomment-3428921

zenoexo commented 12 years ago

Just as a side note, I found that a Gson Type binder that builds out an embedded object that can be saved with PlayMorphia. It goes something like this:

@Global
public class GsonBinder implements TypeBinder<JsonElement> {   
@Override    
public Object bind(String name, Annotation[] annotations, String value,  Class actualClass, Type genericType) throws Exception {        
return new JsonParser().parse(value); 
}}
/* controller */
public static void foo(JsonElement myEmbeddedJson){
  MyDeepEmbeddedClass bar = new Gson().fromJson(myEmbeddedJson, MyDeepEmbeddedClass.class);
  bar.save();
}

If you are dealing with JSON data to begin with this approach can work - if not, won't help.

greenlaw110 commented 12 years ago

Hello since v1.2.7 now is using play 1.2.4 binding mechanism, can anyone of you check if this issue get fixed on 1.2.7+ ?

shoon commented 12 years ago

Edit - Sorry, I wasn't using MorphiaFixtures

As of 1.2.9a I am unable to load in a yaml file that has list of referenced objects. Exception:

com.google.code.morphia.mapping.MappingException: Error mapping field:.... at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:448) at com.google.code.morphia.mapping.Mapper.toDBObject(Mapper.java:430) at com.google.code.morphia.DatastoreImpl.entityToDBObj(DatastoreImpl.java:707) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:755) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:826) at com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:820) at play.modules.morphia.Model.save2(Model.java:729) at play.modules.morphia.Model.save(Model.java:716) at play.modules.morphia.Model._save(Model.java:59) at play.test.Fixtures.loadModels(Fixtures.java:221) ....

eaorak commented 10 years ago

Are there any updates regarding this issue ?