简体   繁体   中英

avoiding multiple selects when using kew word “new” in hql

I have the following code in java.

List<UserHelper> users=List<UserHelper>)session.getNamedQuery("PkUser.loadHelperUsers").list(); ,

I think it does not matter what the "UserHelper" class is that's why I do not write it, not to overload my question. This is my namedQuery mentioned above.

 @NamedQuery(name = "PkUser.loadHelperUsers", query = "SELECT  new ge.tec.pto.ext.helpers.UserHelper(u) from PkUser u order by u.pkUserId desc"),

The problem is that the hql selects too many rows, I think the same number of rows that is in database in pk_user table.If anyone knows how to fix this please inform me. It will be very nice if the solution will not require to alter my "NamedQuery", It will be graet if I will have to change only my Query creation, But any solutions will be helpful, Thank you

Multiple selects when using Key word “`new`” in `hql`


There is no problem with your code and with NEW keyword .

Your query will return all the Rows in the UserHelper related Table

You should use a WHERE clause to get the required rows .

EX :

query = "SELECT  new ge.tec.pto.ext.helpers.UserHelper(u) from PkUser u where username=:passedparamer order by u.pkUserId desc"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM