Re: Error loading Entity containing Collection of @Embed objects that contain a Collection

187 views
Skip to first unread message

Andy DeWolfe

unread,
Oct 15, 2012, 2:04:30 PM10/15/12
to objectify...@googlegroups.com
Sorry for the double post - first time using Google Groups

On Sunday, October 14, 2012 7:45:52 PM UTC-4, Andy DeWolfe wrote:
Hello all.   Newbie ( to Objectify4 ) here.  Objectify4 rocks!

Trying to do a 1-to-many using Colleciton of @Embed's.  Got the general idea from another post in this group.
However, my @Embed class contains it's own collection.  ( using Objectify4.0a4 )

  @Entity
  class Group {

      @Id
      Long id;

      @Embed
      static class GroupPerson {
        @Index
        @Load
        public Ref<Person> person;
        
        public Set<String> roles;         // <---- collection inside @Embed object
      }

      static class GroupPersonMapper implements Mapper< Key<Person> , GroupPerson > {
        @Override
        public Key<Person> getKey(GroupPerson value) {
          return value.person.getKey();
        }
      }
      
      @Mapify(GroupPersonMapper.class)
      @Load
      Map< Key<Person> , GroupPerson > groupMembers;      // <-- collection of @Embed objects
  }
    
    
I can persist this to the dataStore fine, and it even looks "right" in the GAE console.

   groupMembers.roles = [role1,role2] (unindexed)

When i tried to load a Group entity (from a Query), I get the following exception

com.googlecode.objectify.LoadException: Error loading Group(2155): groupMembers.roles: Expected list structure but found {role1,role2}
at com.googlecode.objectify.impl.Transmog.load(Transmog.java:76)
at com.googlecode.objectify.impl.ConcreteEntityMetadata.load(ConcreteEntityMetadata.java:121)
at com.googlecode.objectify.impl.cmd.ObjectifyImpl.load(ObjectifyImpl.java:386)
at com.googlecode.objectify.impl.engine.LoadEngine$Round$2.now(LoadEngine.java:102)
at com.googlecode.objectify.impl.ref.StdRef.get(StdRef.java:57)
at com.googlecode.objectify.impl.cmd.QueryImpl$3.translate(QueryImpl.java:381)
at com.googlecode.objectify.impl.cmd.QueryImpl$3.translate(QueryImpl.java:1)
at com.googlecode.objectify.util.TranslatingQueryResultIterable$1.translate(TranslatingQueryResultIterable.java:31)
at com.googlecode.objectify.util.TranslatingIterator.next(TranslatingIterator.java:35)


Changing Collection from Set<String> to List<String> had no effect.  Should this work?  Am I doing something wrong?

Thanks in advance,
Andy

Alex

unread,
Oct 17, 2012, 2:30:17 AM10/17/12
to objectify...@googlegroups.com
Unfortunately Objectify doesn't like multi-levelled list embedding (assuming it's the error I think it is).
Unless you have the need to query/search it, using @Serialized instead of @Embed will "fix" it.

Alex.

Alex

unread,
Oct 17, 2012, 2:32:50 AM10/17/12
to objectify...@googlegroups.com
Oh lol, Jeff answered your other post w.r.t. @Mapify
In any case - I usually just use @Serialized when I get an error like that - usually fixes it.

Alex.

Andy DeWolfe

unread,
Oct 18, 2012, 9:37:14 AM10/18/12
to objectify...@googlegroups.com
Hi Alex,

In my example, I do want to query for groupPerson.person, but not for groupPerson.roles.  I got my code working by adding @Serialize to the Set<String> roles parameter inside the @Embed GroupPerson class.

Andy
Reply all
Reply to author
Forward
0 new messages