从多个表 ormlite 中获取数据 [英] Fetch data from multiple table ormlite

查看:94
本文介绍了从多个表 ormlite 中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 ORMLite 中编写以下查询

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"),
);

但这会引发异常,即在 T1 中找不到描述"列.而且 T1 中有 T2 对象,并且 @DatabaseField 注释中的 autoRefresh 为真.

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

推荐答案

对于有同样问题的人

我已经通过查询更改解决了这个问题

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");

这篇关于从多个表 ormlite 中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆