Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Name and version of the database you are using:
MySql 4.1, MSSQL
The generated SQL (show_sql=true):
select *, Ended - Started as duration from sessions this_
I need to calculate the duration between two dates (Ended - Started) and have them return in a seperate column. I chose to do this via an SQLProjection:
Code:
criteria.setProjection( Projections.projectionList()
.add(Projections.alias(Projections.sqlProjection("Ended - Started as duration",new String[] {"duration"},new org.hibernate.type.Type[]{Hibernate.TIMESTAMP}),"duration"))
The problem is - this code works well on MSSQL, however on MySQL I receive a ClassCast exception - apparently subtracting dates in MySQL returns a FLOAT.
My question is - how can I make my code work for both databases without reducing it to switch-case clauses? I want to make it as generic as possible.
PS I thought of using DATEDIFF in the SQLProjeciton but the syntax is again different for the two databases.
10x2all