• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use substr function in Criteria

 
pankaj semwal
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • 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 .
 
Hemant Thard
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
MPIM_PART_NO_FRM is a property of class REMPIM_TB .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic