ORMLite mixing orderBy() and orderByRaw()

I want to query a list of items from my database using ORMLite. The ordering must be a bit field, then the nullability of a field, then a date field. Here is what I have at the moment:

 QueryBuilder<Task, Integer> queryBuilder = mTaskDao.queryBuilder();
        queryBuilder
        .orderBy("done", true)
        .orderByRaw("visit_id is null desc")
        .orderBy("duedate", true);

When I call getStatement() on the above query however, it returns the following SQL:

SELECT * FROM `task` ORDER BY visit_id is null

Notice only orderByRaw had an effect on the QueryBuilder. Reading the QueryBuilder code I see method appendOrderBys ignores non RawOrderBy statements, if orderByRaw is non null.

Ideally it should have generated the orderBy and orderByRaw in correct order.

Only workaround I can think of for now is to set all my order by clauses in the orderByRaw() method.

Answers


Notice only orderByRaw had an effect on the QueryBuilder. Reading the QueryBuilder code I see method appendOrderBys ignores non RawOrderBy statements, if orderByRaw is non null.

Yeah. This looks to be a limitation of ORMLite right now. It seems like it either handles the raw or the non. See this code here around like 757.

https://github.com/j256/ormlite-core/blob/e11db21da474e9e0d4004cd83fa9f71c3d4e66e3/src/main/java/com/j256/ormlite/stmt/QueryBuilder.java#L757

This is not documented at all that they are mutually exclusive and I can see no reason why they should be. I've added this bug:

https://sourceforge.net/p/ormlite/bugs/161/

A fix for it has been checked into trunk and was released on 12/16/2013 in version 4.48.

https://github.com/j256/ormlite-core/commit/36492cebc1506b0b75f3a6f72569ec25de776aec


Need Your Help

MongoDB how to become master

mongodb mongodb-query database-replication sharding mongodb-java

I am creating a MongoDB database through a linux terminal and I am trying to create a collection for the database.

How can I insert multiple rows into oracle with a sequence value?

sql oracle

I know that I can insert multiple rows using a single statement, if I use the syntax in this answer.