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.