In DBHelper I created DAOs for all entities like this
public MyEntityDao getMyEntityDao() {
try {
if (mMyEntityDao == null) {
mMyEntityDao = new MyEntityDao(getConnectionSource(), MyEntity.class);
mMyEntityDao.setObjectCache(ReferenceObjectCache.makeSoftCache());
}
} catch (SQLException e) {
e.printStackTrace();
}
return mMyEntityDao;
}
MyEntity class:
@DatabaseTable
public class MyEntity {
...
@ForeignCollectionField(eager = false)
private Collection<MyEntityValue> myEntityValues;
public Collection<MyEntityValue> getMyEntityValues() {
return myEntityValues;
}
...
}
I make a network call, cascade delete all old entities and insert new ones.
Without cache enabled, Collection<MyEntityValue> myEntityValues was an empty/non-empty LazyForeignCollection.
With cache enabled, it is sometimes NULL and causing NPEs in parts of code that previously worked.
Steps to reproduce:
In DBHelper I created DAOs for all entities like this
MyEntity class:
I make a network call, cascade delete all old entities and insert new ones. Without cache enabled,
Collection<MyEntityValue> myEntityValues
was an empty/non-empty LazyForeignCollection. With cache enabled, it is sometimes NULL and causing NPEs in parts of code that previously worked.