开发者

Objectify fails to save @Embedded List of Strings

开发者 https://www.devze.com 2023-02-27 04:08 出处:网络
Objectify (2.2.3) seems to not want to handle @Embedded lists of strings, although all documentation seems to say that it should be possible.

Objectify (2.2.3) seems to not want to handle @Embedded lists of strings, although all documentation seems to say that it should be possible. The strings are handled as if they are custom objects that need to be converted. The minimal example:

public class Test {
  @Id public Long id = null;
  @Embedded private List<String> strings = new ArrayList<String>();

  private Test() {}

  public Test(String[] in) {
    for (String s : in) {
      strings.add(s);
  }
}

An instance of this class gets saved as:开发者_高级运维

  Key: 7
  ID/Name: ahpzY2hlZHVsZS13aXRoLXlvdXItZnJpZW5kc3IKCxIEVGVzdBgHDA   
  strings.hash: [0, 0]

Notice that the strings are saved by hash, it being the only non-final field in a String

This code will fail:

ObjectifyService.register(Test.class);
Test t = new Test(new String[] { "aa", "bb" });
Objectify ofy = ObjectifyService.begin();
ofy.put(t);
Test t2 = ofy.get(Test.class, t.id); //<-- fails with IllegalAccessException: Private fields can not be set on JRE classes.

Am I doing something wrong here? Are Embedded Lists of Strings not supported?


As learned via the objectify-appengine google group: Lists of simple types should not be marked @Embedded. They will be persisted without that notation. @Embedded is only for complex user types. The documentation will be updated to make that mare clear.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号