Home » Support » Forum » order by string with numbers

order by string with numbers

#1

Hi

Anyone could help me I need to order a string  for example user1, user2, ..., user1000

I found sql solution but I would like to use criteria builder and I don´t if exist CAST and AS UNSIGNED

 

The sql that works is

ORDER BY CAST(SUBSTR(username FROM 4) AS UNSIGNED) ASC

Using JPQL SELECT u FROM Users u ORDER BY SUBSTRING(u.username,4)*1 ASC

If you have other alternative for JPA CriteriaBuilder to do it as sql did please let me know.

Thanks

 

#2

It seems that this is not supported by JPA criteria queries.

If you need a solution only for ObjectDB (but a solution that is not JPA compatible) then you can try using functions in your query. Integer.parseInt is supported by ObjectDB in JPQL string queries. You may try using Integer.parseInt as a JPA criteria query functionfunction(name, type, args)CriteriaBuilder's methodCreate an expression for the execution of a database function.See JavaDoc Reference Page....

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login