문제

I'm trying to embed a map in an entity with Objectify 4 (and GAE SDK 1.9.0).

The docs (here) show stuff like this:

@Embed
class LevelTwo {
    String bar;
}

@Entity
class EntityWithEmbeddedCollection {
    @Id Long id;
    List<LevelOne> ones = new ArrayList<LevelOne>();
}

So first I tried to do the same thing but with a HashMap< Long, LevelTwo >. This resulted in a runtime error when I tried to save the entity.

Then I read about @EmbedMap, which is a recent addition to ofy. So then I tried the following formlation:

class LevelTwo {
    Integer one;
    Boolean bee;
}

class EntityWithEmbeddedCollection {
    @Id Long id;
    @EmbeddedMap
    Map<Long, LevelTwo> ones = new HashMap<Long, LevelTwo>();
}

I also tried this with LevelTwo as an inner static class and a few other variations, but I always get:

com.googlecode.objectify.SaveException:
Error saving com.myapp.UserInfoSvr@96: items: java.util.HashMap is not a supported property type.
    at com.googlecode.objectify.impl.Transmog.save(Transmog.java:105)

Any suggestions?

도움이 되었습니까?

해결책 2

@EmbedMap only works with String keys, and it works by creating an property on the entity that looks like "foo.bar.yourkeyhere". It's not a very sophisticated mechanism.

What exactly are you trying to do? You may also wish to consider the Mapify annotation and an embedded collection.

다른 팁

Readers should note that on 2014-03-28 Objectify 4.1 was released and it makes a major change in the handling of embedding (which is relevant to this post). It is a major improvement that was facilitated by a fairly recent improvement in Google's low-level datastore API.

The announcement is here:
https://groups.google.com/forum/#!topic/objectify-appengine/sbhig-wCDnI

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top