-->
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.  [ 5 posts ] 
Author Message
 Post subject: any way to call database built in function in hibernate
PostPosted: Fri Mar 03, 2006 12:25 pm 
Newbie

Joined: Fri Mar 03, 2006 12:19 pm
Posts: 3
is there a way to call database built in funtions in hibernate query? thanks for any input.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 12:33 pm 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Your question is a bit vague, I'm thinking about native SQL queries session.createSQLQuery() or formula mapped properties <property name="propertyName" formula="SQL statement"/>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 12:46 pm 
Newbie

Joined: Fri Mar 03, 2006 12:19 pm
Posts: 3
Suppose I have a query: SELECT * FROM exchange_pp WHERE TIMESTAMPDIFF(hour, last_updt_dt,now()) <96, which will get data for the past 96 hours. TIMESTAMPDIFF is mysql built in functoin.

I have POJO for this table with field last_updt_dt. How could I create Hiberante query to get the same data as I used above query.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 2:00 pm 
Regular
Regular

Joined: Wed Feb 08, 2006 3:59 pm
Posts: 75
Unless you have a religious reason to use MySQL built in functions, it will be easier to do something like that :

Code:
Date date = new Date(System.currentMillis() - 96 * MILLISECONDS_IN_AN_HOUR);
String hql = "from Exchange e where e.lastUpdate > :=date";
List result = session.createQuery(hql).setDate("date", date).list();


Maybe there is an HQL construct to avoid the "new Date()" by I don't know it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 03, 2006 2:17 pm 
Newbie

Joined: Fri Mar 03, 2006 12:19 pm
Posts: 3
thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.