• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using MOD in JPQL  RSS feed

PaulN Pearson
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!