-->
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: Oracle Functions in Criteria Expression
PostPosted: Wed Nov 03, 2004 12:55 pm 
Newbie

Joined: Wed Sep 01, 2004 2:03 pm
Posts: 7
Hibernate version: 2.1

I am trying to do something in the Crieria API that works great in HQL

Here is the HQL version:

"from Product prod where prod.year = currentyear()"

currentyear() is an Oracle function that returns the current year

Now, I want to move this query into the Criteria API. Here's my attempt that doesn't work:

.createCriteria(getSession(),Product.class)
.add(Expression.eq("year","currentyear()"))
.list();

This doesn't work because hibernate translates this into "... year = ?" and current year doesn't get evaluated as a function.

Can someone please tell me how to accomplish this? I'm sure someone else has tried to do this before.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 08, 2004 3:22 pm 
Newbie

Joined: Wed Sep 01, 2004 2:03 pm
Posts: 7
I found the answer on my own. You can use the Expression.sql() to call a native SQL expression. So my code uses:


.add(Expression.sql("year = currentyear()"))


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.