-->
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.  [ 6 posts ] 
Author Message
 Post subject: Date type and hql
PostPosted: Thu Oct 20, 2005 5:04 am 
Sorry, for my bed english... help me

in hql - query used NullableDateTime type and exist compared date string.
example:

from a as a
where a.Date > ???

I have string contains date, what i can build query without typecast exception?


Top
  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 8:13 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Queries can also take strings... So, if you have a string then use it.
One example:
Code:
from MyEntity e where e.Date > '2005-10-20'

Read the SQL documentation to see how the date should be presented...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 12:22 pm 
I'm writing an Candidature Manager application which can use a SQL Server or Firebird database to store the datas.

I want to write an HQL query which search for a Candidature list which have a date > A_DATE.

But I have some matter because of the difference between date format in
the 2 databases. Indeed, the date format are :
* SQL Server : 'dd/MM/yyyy'
* Firebird : 'MM/dd/yyyy'

So this HQL query is Ok with one database and thrown an exception with the other :
Code:
"SELECT c FROM Candidature as c WHERE c.Date > 10/20/2005'"


Is it possible to set change the date format of a database with NHibernate ?

Because I don't want to be forced to do something like this :
Code:
string str;
if (SQL Server)
  str = date.ToString("dd/MM/yyyy");
else
  str = date.ToString("MM/dd/yyyy");


Top
  
 
 Post subject:
PostPosted: Thu Oct 20, 2005 3:43 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You should be able to build a parametrized query just fine. Use Nullables.NHibernate.NullablesTypes.NullableDateTime if you need an IType parameter to some call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 21, 2005 8:31 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I had a similar problem one time: I had to use date on english and french systems (always with SQL Server); I had trouble to tell SQL Server which format to use and I finally found that YYYYMMDD is culture-independent (eg: 20050102 is always the 2th january 2005).

You may try this and see if it works on Firebird...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 22, 2005 3:46 am 
Yes KPixel,
I search on the web and found the ISO date format which is yyyymmdd but I think SQL Server 2000 don't recognize it anymore because I have the same problem.

So I changed the language of my login in SQL Server via the "sp_defaultlanguage" function of SQL Server.


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