ORMLite : Internal DAO object is null

后端 未结 2 341
不知归路
不知归路 2021-01-14 03:15

I\'m using ORMLite, trying to use the ForeignCollectionKey but I got the following error :

Internal DAO object is null. LazyCollections cannot be use

相关标签:
2条回答
  • 2021-01-14 03:56

    Do you have any ideas ? Is my model construction right ? Thanks

    So the exception message is trying to explain what is going on. I'm not sure how it can be improved.

    Internal DAO object is null. LazyCollections cannot be used if they have been deserialized.

    You are trying to access zoneChild which is a ForeignCollection that has been deserialized. Since it has been deserialized all of the underlying database configurations and connections could not be reestablished. I guess this can happen when it stored in an Android Bundle? I'm not sure if this is the only case.

    If you need to get the Zone children you are going to have to either call dao.refresh() on the entity after you deserialize it or do the query yourself by doing the zoneDao.

    0 讨论(0)
  • 2021-01-14 04:15

    I solved this problem like Gray suggested: pass the primary key attribute in the Bundle and then obtain the object again from the database in the destination Activity:

    Example:

    Let's suppose I want to pass a Person object and that I've declared Person.name as:

    @DatabaseField (columnName ="name")
    private String name;
    

    Then:

    ActivityA

    Intent intent = new Intent(ActivityA.this, ActivityB.class);
    Bundle bundle = new Bundle();
    bundle.putString("NAME" Person.getName());
    intent.putExtras(bundle);
    

    ActivityB

    String name = getIntent().getExtras().getString("NAME"));
    Person p = getHelper().getPersonDao().queryForEq("name", name);
    

    And there you are, your Collection will be refreshed.

    0 讨论(0)
提交回复
热议问题