Fetch data from multiple table ormlite

只谈情不闲聊 提交于 2019-12-13 04:44:05

问题


I need to write following Query in ORMLite

SELECT * FROM T1 t1, T2 t2 where t1.id = t2.id AND t1.type='abc' AND (t1.title = 'XYZ' OR t2.description = 'xyz');

However So Far I have been able to write following code:

QueryBuilder<T1, Integer> t1QB = getT1Dao().queryBuilder();
QueryBuilder<T2, Integer> t2QB = getT2Dao().queryBuilder();
t1QB.join(t2QB);
Where<T1, Integer> where = t1QB.where();
where.eq("Type", "abc");
where.and().or(
    where.ne("title", "XYZ"),
    where.ne("description", "xyz"),
);

but this throws exception that column not found "description" in T1. And also T1 has T2 object in it and autoRefresh is true in @DatabaseField annotation.

Is there is any way to do this with above method or I have to write custom Query


回答1:


For people with same problem

I have resolved this problem with change in query

SELECT * FROM T1 WHERE type='abc' AND (title = 'XYZ' OR id IN (SELECT id from T2 where description = 'xyz'));


QueryBuilder<T1, Integer> t1QB = getT1Dao().queryBuilder();
QueryBuilder<T2, Integer> t2QB = getT2Dao().queryBuilder();
t2QB.where().eq(id, id);

Where<T1, Integer> where = t1QB.where();
where.or(
     where.ne("title", "XYZ"),
     where.in("id", t2QB);
);
where.and().eq("Type", "abc");


来源:https://stackoverflow.com/questions/27294725/fetch-data-from-multiple-table-ormlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!