• 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

Use substr function in Criteria

 
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi List,
i want to use substr fucntion inside criteria i try like this but its not works.



And i want the sql should be like this :



Please tell me .
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi pankaj,

I am not sure if this is the right way to declare substr function inside criteria(I myself is a fan of MYSQL and this query is not supported there ..).
but i just want to comment on your query


add(Restrictions.between("substr(MPIM_PART_NO_FRM,0,5)", fromPart.substring(0, 5), fromPart.substring(0, 5)))
.add(Restrictions.between("substr(MPIM_PART_NO_TO,0,5)", toPart.substring(0, 5), toPart.substring(0, 5)));



is it the right way you have declared your criteria. Please check.
because with this query, even if there is no error, will always return null.

Regards,
Hemant.
 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i run above criteria its showing exception as


org.hibernate.QueryException: could not resolve property: substr(MPIM_PART_NO_FRM,0,5) of: hmil.com.partmaster.model.REMPIM_TB
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:67)

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

I just want to check with you whether "MPIM_PART_NO_FRM" is property of your class or its a column in table.

Because hibernate expects you to use class property in your Query instead of table column .


Please confirm.

Regards,
Hemant
 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MPIM_PART_NO_FRM is a property of class REMPIM_TB .
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic