无法编译 ORMLite 语句

Can't compile ORMLite statement

我正在尝试编译 ORMLite 查询语句,但我得到以下 SQLException:

Could not compile this SELECT_LONG statement since the caller is expecting a SELECT statement.  Check your QueryBuilder methods.

我已经尝试了所有可能的方法,但我总是能做到,我的主要尝试是:

QueryBuilder<Message, Integer> messagesQueryBuilder = dbManager.getMessagesDao().queryBuilder();   
Where<Message, Integer> resultedQuery = messagesQueryBuilder.where().in(Message.SCHOOL_COLUMN_NAME, schoolIntegerQueryBuilder);
Long count = messagesQueryBuilder.countOf();
messagesQueryBuilder.orderBy(Message.MESSAGE_TIMESTAMP, false);
messagesQueryBuilder.queryForFirst(); // getting it here

然后我尝试先准备查询:

messagesQueryBuilder.orderBy(Message.MESSAGE_TIMESTAMP, false);
Message message = dbManager.getMessagesDao().query(messagesQueryBuilder.prepare()).get(0); // getting here also 

最后尝试在一个新对象中单独准备它,然后使用该对象:

PreparedQuery<Message> queryForMessage = messagesQueryBuilder.orderBy(Message.MESSAGE_TIMESTAMP, false).prepare();
Message message = dbManager.getMessagesDao().query(queryForMessage).get(0); // also failing here with the same Exception

我不知道我到底做错了什么,但尽管我尝试了所有可能的正常工作方式。

终于找到问题出在哪里了,在ORMLite中执行一个方法就像是执行一条语句,不仅仅是获取值存储到别处,所以执行时:

Long count = messagesQueryBuilder.countOf();

现在 messagesQueryBuilder 只包含检索到的计数,而不是之前存储在其中的整个查询结果。

因此,为了解决我的问题,我将代码执行行重新排序如下:

QueryBuilder<Message, Integer> messagesQueryBuilder = dbManager.getMessagesDao().queryBuilder();   
Where<Message, Integer> resultedQuery = messagesQueryBuilder.where().in(Message.SCHOOL_COLUMN_NAME, schoolIntegerQueryBuilder);

messagesQueryBuilder.orderBy(Message.MESSAGE_TIMESTAMP, false);
Message message = messagesQueryBuilder.queryForFirst();

Long count = messagesQueryBuilder.countOf();