如何将休眠连接查询转换为 ormlite 查询
How to convert hibernate join query to ormlite query
我有一个休眠查询,它根据特定条件使用其模型 class 从两个表中选择特定数据。现在我想将该查询转换为 ORMLite 查询以在我的 android 应用程序中使用,但我不知道如何在 ORMLite 中使用 queryBuilder() 来完成它,因为我是 ORMLite 的初学者。
Query query = getCurrentSession().createQuery(
"SELECT A.accountID,A.name,B.allowTransactions from Payments A,Accounts B "
+ "WHERE A.accountID=B.id AND B.id NOT IN (5,55,602) AND A.active=1 AND "
+ "B.parentID=:pID AND B.date BETWEEN :sDate AND :eDate GROUP BY A.id "
+ "ORDER BY CASE WHEN A.name=:name THEN 1 ELSE 0 END,A.name");
query.setParameter("pID",4);
query.setParameter("name", "Others");
query.setParameter("sDate",startDate);
query.setParameter("eDate", endDate);
下面是 getter 付款和账户的方法 classes。
dbHelper.getPaymentDao() and dbHelper.getAccountDao()
I have a hibernate query which selects particular data from two tables using its model class based on certain conditions. Now i want to convert that query to ORMLite query...
鉴于其复杂性,ORMLite QueryBuilder
不支持此查询。您当然可以使用 dao.queryRaw(...)
method 然后自己手动处理结果。
GenericRawResults<String[]> results = paymentDao.queryRaw(
"SELECT A.accountID,A.name,B.allowTransactions from Payments A,Accounts B "
+ "WHERE A.accountID=B.id AND B.id NOT IN (5,55,602) AND A.active=1 AND "
+ "B.parentID=? AND B.date BETWEEN ? AND ? GROUP BY A.id "
+ "ORDER BY CASE WHEN A.name = ? THEN 1 ELSE 0 END,A.name",
parentId, fromDate, toDate, name);
请注意,我已将 : 参数转换为 ?
个参数。
returns String
结果,但您也可以使用其他 Dao.queryRaw(...)
方法将结果正确转换为 Java 个实体。
我有一个休眠查询,它根据特定条件使用其模型 class 从两个表中选择特定数据。现在我想将该查询转换为 ORMLite 查询以在我的 android 应用程序中使用,但我不知道如何在 ORMLite 中使用 queryBuilder() 来完成它,因为我是 ORMLite 的初学者。
Query query = getCurrentSession().createQuery(
"SELECT A.accountID,A.name,B.allowTransactions from Payments A,Accounts B "
+ "WHERE A.accountID=B.id AND B.id NOT IN (5,55,602) AND A.active=1 AND "
+ "B.parentID=:pID AND B.date BETWEEN :sDate AND :eDate GROUP BY A.id "
+ "ORDER BY CASE WHEN A.name=:name THEN 1 ELSE 0 END,A.name");
query.setParameter("pID",4);
query.setParameter("name", "Others");
query.setParameter("sDate",startDate);
query.setParameter("eDate", endDate);
下面是 getter 付款和账户的方法 classes。
dbHelper.getPaymentDao() and dbHelper.getAccountDao()
I have a hibernate query which selects particular data from two tables using its model class based on certain conditions. Now i want to convert that query to ORMLite query...
鉴于其复杂性,ORMLite QueryBuilder
不支持此查询。您当然可以使用 dao.queryRaw(...)
method 然后自己手动处理结果。
GenericRawResults<String[]> results = paymentDao.queryRaw(
"SELECT A.accountID,A.name,B.allowTransactions from Payments A,Accounts B "
+ "WHERE A.accountID=B.id AND B.id NOT IN (5,55,602) AND A.active=1 AND "
+ "B.parentID=? AND B.date BETWEEN ? AND ? GROUP BY A.id "
+ "ORDER BY CASE WHEN A.name = ? THEN 1 ELSE 0 END,A.name",
parentId, fromDate, toDate, name);
请注意,我已将 : 参数转换为 ?
个参数。
returns String
结果,但您也可以使用其他 Dao.queryRaw(...)
方法将结果正确转换为 Java 个实体。