-->
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: Bug in SQL Server & Sybase date/time functions
PostPosted: Wed May 25, 2005 12:39 am 
Newbie

Joined: Sun Jan 30, 2005 9:43 pm
Posts: 16
Hibernate version: 3.0

Code between sessionFactory.openSession() and session.close():

Code:
// Get the first message that is ready to be processed from a queue.
Message msg = (Message)session.createFilter(queue.getMessages(),
                    "where ProcessAt >= current_timestamp() order by ProcessAt asc")
                    .setMaxResults(1)
                    .uniqueResult();


Name and version of the database you are using:
SQL Server 2000 SP1 v8.00.194 Developer Edition

The generated SQL (show_sql=true):
Hibernate: select top 1 eviemessag0_.MessageId as MessageId, eviemessag0_.MsgText as MsgText14_, eviemessag0_.ProcessAt as ProcessAt14_, from QueueMessage messages1_ inner join Message eviemessag0_ on messages1_.MessageId=eviemessag0_.MessageId where messages1_.QueueId = ? and ProcessAt>=getdate order by ProcessAt asc

Debug level Hibernate log excerpt:
12:48:50,457 WARN JDBCExceptionReporter: SQL Error: 207, SQLState: 42S22
12:48:50,457 ERROR JDBCExceptionReporter: Invalid column name 'getdate'.

The portable current_timestamp() function should be mapped to getdate() rather than getdate .


In the Hibernate 3.0 source code, it appears that the date/time functions registered in org.hibernate.dialect.SybaseDialect.SybaseDialect()

Code:
registerFunction( "current_timestamp", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP, false) );
registerFunction( "current_time", new NoArgSQLFunction("getdate", Hibernate.TIME, false) );
registerFunction( "current_date", new NoArgSQLFunction("getdate", Hibernate.DATE, false) );
registerFunction( "getdate", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP) );


... should be ...

Code:
registerFunction( "current_timestamp", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP) );
registerFunction( "current_time", new NoArgSQLFunction("getdate", Hibernate.TIME) );
registerFunction( "current_date", new NoArgSQLFunction("getdate", Hibernate.DATE) );
registerFunction( "getdate", new NoArgSQLFunction("getdate", Hibernate.TIMESTAMP) );


In SQL Server 2000 - the following return the same value:
Code:
   select current_timestamp   
   select getdate() 


But the following is invalid:
Code:
  select getdate


... but this is what Hibernate 3.0 is generating.

Sybase & SQL Server only supports a datetime type (not date or time types).

This will return current_date as a datetime value:
Code:
select CAST (CAST (getdate() as integer) as datetime)


Getting the current_time in a single expression would be a bit harder and I'm on a tight timeline at the moment.
Check out http://www.karaszi.com/SQLServer/info_datetime.asp

Thanks for Hibernate.
Tony.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 2:40 am 
Newbie

Joined: Sun Jan 30, 2005 9:43 pm
Posts: 16
Looks like this has been partially fixed in 3.0.5 but I'm not sure that the issues with current_time and current_date have been fully dealt with.


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.