• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using MOD in JPQL

 
PaulN Pearson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a long variable mapped to a database column, representing a date and time, in the form YYYYMMDDhhmm. So for example, midday today would be represented by the long value 200911051200L.

I need to be able to run queries using JPQL against each of the individual components - year, month, etc. In order to access the month, for example, I was hoping to be able to do "MOD(value, 100000000) / 1000000".

The problem with this is that the MOD function in JPQL appears to be only valid for integers, not longs. Alternatively, I tried doing the division first, which gave me a smaller number (one that would fit into an int), and then doing the MOD. However, the result of the division is still considered to be a java.lang.Long which can't be cast to an Integer. So that didn't work either.

Can anyone help me come up with a good way of doing these queries using JPQL? Changing the way data is stored in the database isn't an option. Doing the arithmetic in Java is undesirable.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!