[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Re: JPQL:
ethnarch
do-not-reply at jboss.com
Fri Apr 17 14:29:19 EDT 2009
I would go look this up for you normally but I can't find the documentation on hibernate right now.
I think HQL might have a mod operator and I think this is what you actually want to use. I can't verify it it really exists though.
The mod operator returns the remainder so 5 mod 2 = 1 and 3 mod 2 = 1
So you would look for anything (s.age mod 10)=:age to find any ages that end in a certain number.
Most databases that I know of have some form of the mod operator for instance sql server
http://www.tek-tips.com/viewthread.cfm?qid=1213610&page=10
and oracle
http://www.techonthenet.com/oracle/functions/mod.php
If it does exist then you would be able to do something like this
SELECT s FROM Student s WHERE mod(s.age,10)=:age
I suspect that this would be faster than a string comparison and conversion however, I am not sure either.
Actually I think i found some documentation half way down this page
http://doc.javanb.com/hibernate-reference-3-2-4-sp1-en/queryhql.html
anonymous wrote : Any function or operator defined by EJB-QL 3.0: substring(), trim(), lower(), upper(), length(), locate(), abs(), sqrt(), bit_length(), mod()
There is always more than one way to do things but hopefully this helps you.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4226275#4226275
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4226275
More information about the jboss-user
mailing list