mysql - Java hibernate query issues with order by clause -


hi using hibernate query , trying results order id, getresultlist function returning result in ascending order though query has order clause of deviceactivitylogid.

here function

public list<deviceactivitylog> getactivitylogforsysactivityid(int userdevicerelid,int sysactivityid, int parentid, boolean deleteflag) {        string query = "select d deviceactivitylog d d.userdevicerelid = :userdevicerelid  , d.deleteflag = :deleteflag";        if (sysactivityid > 0) {            query += " , d.sysactivityid = :sysactivityid";        }        if (parentid >= 0) {            query += " , d.isparent =:parentid";        }        typedquery<deviceactivitylog> devicequery = entitymanager.createquery(query, deviceactivitylog.class);        devicequery.setparameter("userdevicerelid", new userdevicerel(userdevicerelid));        devicequery.setparameter("deleteflag", deleteflag);        if (sysactivityid > 0) {            devicequery.setparameter("sysactivityid", new sysactivity(sysactivityid));        }        if (parentid >= 0) {            devicequery.setparameter("parentid", parentid);        }        query+=" order d.deviceactivitylogid desc";         system.out.println("query: "+query);         return devicequery.getresultlist();    } 

can provide soultion how result list in descending order?

you're assigning new value query string variable after typedquery object has been created previous value of query variable.

this equivalent to

string message = "hello"; system.out.println(message); message += " world"; 

that print hello, not hello world.

it print hello world if code was

string message = "hello"; message += " world"; system.out.println(message); 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -