JOOQ combining Field and SortField ok?

I am trying to select a list of random records from a MySQL table, but taking precedence over certain ENUM types. It works great when I run the following simple SQL query in the terminal:

select * from table_name where expires <= UNIX_TIMESTAMP()*1000 
order by enum_type desc, rand() limit 500;

      

But I am getting compile error from my IDE when I write the following code:

private List<FooRecord> getNextRecordsWeighted(Condition condition, int recordLimit) {
    final long timeNow = System.currentTimeMillis();
    return context.selectFrom(TABLE_NAME).where(TABLE_NAME.EXPIRES.lessOrEqual(timeNow)).
        orderBy(TABLE_NAME.ENUM_TYPE.desc(), DSL.rand()).limit(recordLimit).fetch();
}

      

Now, what my IDE says, it is obvious that there is no compatible method that I can call to do this. How can I solve this? Is there a workaround?

+3


source to share


1 answer


The problem stems from various method overloads orderBy()

. You have:



Your TABLE_NAME.ENUM_TYPE.desc()

is SortField

, while it DSL.rand()

is Field

. To make this work, you need to do DSL.rand()

a SortField

, causing: DSL.rand().asc()

.

I understand that this is somewhat of a flaw in the API that could probably be fixed in a future version of jOOQ. I created a GitHub issue for this fix: # 3631

+3


source







All Articles