-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate/JPA RIGHT() function with CriteriaBuilder
PostPosted: Tue Jan 15, 2013 6:29 pm 
Newbie

Joined: Mon Jan 14, 2013 4:07 pm
Posts: 17
How would I mimic a RIGHT() function in a query using the JPA CriteriaBuilder? I see the #length and #substring methods but I can't figure out how to do the following:
Code:
     SUBSTRING( field, LENGTH( field ) - 7 )


I'm trying to get the last 7 characters of a field for comparison. Can this be done using CriteriaBuilder or do I need to resort to a text string query expression?

TIA,

R.


Top
 Profile  
 
 Post subject: Re: Hibernate/JPA RIGHT() function with CriteriaBuilder
PostPosted: Tue Jan 15, 2013 7:51 pm 
Newbie

Joined: Mon Jan 14, 2013 4:07 pm
Posts: 17
Ok, found the diff and literal methods. I should have found this sooner:

Code:
   exp = builder.substring( field, builder.diff( builder.length( field ), 7 ) );


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.