markov wrote:
Which is the fastest way to get the database time?
How to execute queries like "select getdate()" or "select systime from dual" in hibernate?
If you want to execute the SQL directly without trying some workaround in HQL, this is how to do it:
(Of course, you could abstract this into two functions, one private that accepts a sql string parameter and one public that calls the private. This would allow you to have multiple functions without rewriting the command and reader objects.)
Code:
public static DateTime CurrentDateTime()
{
System.Data.IDbCommand cmd =
_yourSessionObject.Connection.CreateCommand();
cmd.CommandText = "select sysdate from dual";
System.Data.IDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
return (DateTime)rdr[0];
else
throw new InvalidOperationExeception();
}