Question

I've discovered PARSENAME function as a good choice to order IP address stored in Database. Here there is an example.
My issue is I'm using Hibernate with named queries in a xml mapping file and I am trying to avoid the use of

session.createSQLQuery(..) 

function.
I'm wondering if exists any PARSENAME equivalent function for HQL queries. I'm searching for it and cannot find anything.
Many thanks.

Was it helpful?

Solution

I didn't find anything related.
Finally I executed the following ORDER BY clause to order the IP addresses in numeric way (I found the solution here):

order by cast(substring(host.ip, 1, locate('.', host.ip) - 1) as integer),
                 cast(substring(host.ip, locate('.', host.ip) + 1, locate('.', host.ip, locate('.', host.ip) + 1) - locate('.', host.ip) - 1) as integer),
                 cast(substring(host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1, locate('.', host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1) - locate('.', host.ip, locate('.', host.ip) +  1) - 1) as integer),
                 cast(substring(host.ip, locate('.', host.ip, locate('.', host.ip, locate('.', host.ip) + 1) + 1) + 1, 3) as integer)    

OTHER TIPS

Subclass your dialect and use RegisterFunction() to make PARSENAME available to HQL queries. RegisterFunction is not very well documented but there are plenty of examples on the web. I'm not sure you can use it to order results though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top