关于android:ORMLite外域创建时为空,查询时不为空 | 珊瑚贝

ORMLite foreign field null on create, not null on query


当通过 ORMLite 将我的数据类的一个实例写入数据库,并且其中一个子成员(外部字段)为空时,我得到一个非空子成员。

数据类如下:

1
2
3
4
5
6
7
8
9
10
11
12
public class Site {
    //  snip
    @DatabaseField(foreign = true, canBeNull = true)
    private InstallationType installationType;
}

public class InstallationType {  
    @DatabaseField(generatedId = true)
    private int id;
    @DatabaseField
    private String name;
}

当我通过

再次读取 Site 类的实例时

1
getSiteDao().queryForId(id);

installationType 成员不为空,但 ID 不存在。我们的应用程序的其余部分现在可以使用此对象的唯一方法是,如果我通过 InstallationTypeDAO 手动进行查找并设置我在站点上返回的内容。根据文档,查询有时会返回 null。

有没有办法让 ORMLite 将此成员设置为 null?


这是 ORMLite 中的一个错误,已在 4.15 版(2011 年 3 月 7 日)中修复。这是更改日志文件。你用的是什么版本?你试过更新吗?这是错误报告页面:

目前以下测试通过了,所以我认为我们对该错误有很好的覆盖。

1
2
3
4
5
6
7
8
9
10
@Test
public void testForeignNull() throws Exception {
    Dao<Foreign, Integer> dao = createDao(Foreign.class, true);
    Foreign foreign = new Foreign();
    foreign.foo = null;
    assertEquals(1, dao.create(foreign));
    Foreign foreign2 = dao.queryForId(foreign.id);
    assertNotNull(foreign2);
    assertNull(foreign2.foo);
}

Foreign 具有以下字段:

1
2
3
4
@DatabaseField(generatedId = true)
public int id;
@DatabaseField(foreign = true)
public Foo foo;

如果您的版本是最新的,请告诉我您是否可以更改测试以使其失败。

  • 我正在使用 4.30。 (与 HelloAndroidNoBase 示例一起打包的版本。)现在将尝试 4.35。
  • 升级到 4.35 解决了这个问题。谢谢格雷。


来源:https://www.codenong.com/9701428/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9349.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?