-->
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: get Current Date and limit number of rows returned USING HQL
PostPosted: Mon May 07, 2007 5:51 am 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
Hi ,


no i was wondering if we can swap database easily by only changing configuration files in Hibernate.


Because for example like gettting the current date from the database using hql is not straight forward


Since i m using SQL Server and using SQLServerDialect then my hql should be " select getDate() from something "

because using "current_date/ sysdate doesnt work for me"
What if i want to change to oracle?
i have to change my application code then..


Secondly , how do i limit number of rows using HQL which is portable across database

i use " select top 1 variable from table" doesnt work for me even though i use sql server?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 9:53 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
Hi just_a_kid,
use formula since the current is not associated with a column that you provide (but the system). Try this:
1/ in your mapping file (from Oracle point of view) :
Code:
<property name="currentDate" formula="(select sysdate from dual)"/>

with corresponding getter/setter
2/ in your query:
Code:
session.createQuery("select p.currentDate from Person2 p")


hope this helps

_________________
chucky

Don't forget to rate if this helps
-----------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 10:00 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
Hi just_a_kid,
for the second question:
Code:
Query q = sess.createQuery("from Person");
q.setFirstResult(20);
q.setMaxResults(10);
List pers = q.list();

_________________
chucky

Don't forget to rate if this helps
-----------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 07, 2007 9:19 pm 
Newbie

Joined: Tue Jul 11, 2006 10:41 pm
Posts: 11
Hi Chucky,

Thanks for your help but this is not really what i wanted
and the select sysdate from dual would not work because i am using SQL Server.


Now i realise that hibernate is purely ORM tool and does not really promote database independence such as write HQL that can be used across database

it still relies on the dialect for example if you are using SQL Server Dialect you can getDate() to get the current date from the system

But tthe problem is if my customer want to swap the database to Oracle someday i still have to change my application code / HQL instead changing only the configuration.


Am i Correct?
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 08, 2007 4:10 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
Hi just_a_kid,
since you're just accessing a normal property from the application code side, you won't need to modify any code. Just the SQL in the formula (.hbm.xml the configuration file)

_________________
chucky

Don't forget to rate if this helps
-----------------------------------


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.