• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Using MOD in JPQL

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic