GreenDao & Triggers strange behaviour

366 Views Asked by At

I'm using greendao in my android app and I need to work with triggers. The trigger updates a field after an insert with some info.

DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(context, toString(), null) {
        @Override
        public void onCreate(SQLiteDatabase db) {
            super.onCreate(db);

            db.execSQL("CREATE TRIGGER tg1 AFTER INSERT ON table1 " +
                    "BEGIN " +
                    " update tabl1 set info='" + someInfo + "'" +
                    " where _id=New._id; " +
                    " END;");

            db.execSQL("CREATE TRIGGER tg2 AFTER UPDATE ON table1 " +
                    "BEGIN " +
                    " update table1 set info='" + someInfo+ "'" +
                    " where _id=New._id; " +
                    " END;");


        }
    };
    daoSession = new DaoMaster(helper.getWritableDatabase()).newSession();

The triggers are working well, and when I look directly at the data contained in the table, the field contains the updated info. The problem I'm having is that if I load entities from the table, sometimes I receive data in the field, and sometimes I receive null.

I suppose that this problem has something to do with the session lyfecicle, maybe greendao is not loading the data always from the table, instead it uses objects that are already in memory. I've tested that if I force a refresh of an entity with myDao.refresh(entity), the right value is there.

But I can not force the refresh of the entities when I work with lists (raw queries or loadAll methods).

Is there a way to force green dao to load always fresh info from the database?

Thanks in advance.

1

There are 1 best solutions below

0
On BEST ANSWER

Try cleating the session.

daoSession.clear();