• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

to_char() function in select statement of JPQL

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am a newbie to JPA specifically and O/R in general. I haven't been able to pass this bumper. I need some help here.

Could you tell me whether it is possible to use to_char() function in the native query using Oracle TopLink?
Basically, I have been trying to convert an entity attribute(in java.sql.Date type) to String using to_char() function unsuccessfully. For instance, I have some thing like following:


You can apparently see that I am trying to convert o.timestamp variable from Date object to String type, so I can compare against my filter.timestampStr String parameter using LIKE keyword. That is, records could be counted if filter.timestampStr matches lexicographically.

But Oracle TopLink keeps complaining about the 'to_char' term. It does not recognize it...... to_char unexpected character...

Thanks a lot.
Frank

P.S: Please ignore any typo I might have. I am manually typing that code block.
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JPQL does not support a to_char function. For a list of JPQL functions see,

http://en.wikibooks.org/wiki/Java_Persistence/JPQL_BNF#Functions

You can use a native SQL query (createNativeQuery()).

If you use EclipseLink 2.1, there is support for a FUNC operator that allow usage of any database function. This was also supported from the JPA 2.0 Criteria API in EclipseLink 2.0.
You can also use an EclipseLink/TopLink Expression query, which does support toChar().
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic