jah_404 wrote:
Thank to your post, I realized that using native sql request depends on the DBMS
As I'm using SQL Server, the way to get the hour of a date is :
Code:
session = HibernateUtil.currentSession();
String sql_query = "SELECT" +
" DATEPART(hh,DH_departTrain) AS hour," +
" Id" +
" FROM Circulation" +
" WHERE Id = 1722";
@SuppressWarnings("unchecked")
Query query = session.createSQLQuery(sql_query)
.addScalar("hour", Hibernate.INTEGER)
.addScalar("Id", Hibernate.INTEGER);
hi, Jah_404
yes, you can use DATEPART function to get the hour of a date, if you are using SQL Server.
but I think this is not a good thing, if you migrate your data from SQL Server to Oracle one day.
so, maybe you should figure out another solution that is Independent of DBMS.