在一對一或一對多關係中, 若是新建一個對象 其中的子對象是不會建立的 ,GreenDao 爲咱們提供了相應的get方法 數據庫
例如 測試
@Generated(hash = 1538855097) public Person getPerson() { String __key = this.personInfoId; if (person__resolvedKey == null || person__resolvedKey != __key) { final DaoSession daoSession = this.daoSession; if (daoSession == null) { throw new DaoException("Entity is detached from DAO context"); } PersonDao targetDao = daoSession.getPersonDao(); Person personNew = targetDao.load(__key); synchronized (this) { person = personNew; person__resolvedKey = __key; } } return person; }
你們能夠看到 須要設置daoSession this
我測試了下對象
/** * called by internal mechanisms, do not call yourself. */ @Generated(hash = 1722282747) public void __setDaoSession(DaoSession daoSession) { this.daoSession = daoSession; myDao = daoSession != null ? daoSession.getPersonInfoDao() : null; }
手工設置了下DaoSession 是能夠在建立對象的, 其實也不算是建立對象而是在數據庫中查不到相應的數據。get
註釋上說 不要咱們本身去建立, 而是在greendao 查詢的時候由greendao 來肯定的hash
因此咱們能夠 在構造方法中加入 it
recordChoice = new ArrayList<>();
這樣來初始化數據 io
可是這樣greendao 也會訪問, 而報錯, 而後加上 List
@Keep
就萬事大吉了方法