After daily dealing with EJB 3.0 and after a long “experience” in the core field which it is EJB basically. it turned out that sometimes I have to do some work arounds (In some cases) mostly EJB-QL. When we compare JBoss Hibernate-QL and EJB-QL we can see this missing gap in the EJB-QL specification. Let’s have an example which shows one of the missing gaps in EJB-QL.
EJB-QL date comparison
when we say date comparison in the most cases it’s like this
[sql]SELECT p FROM Person p WHERE p.birthday = :date[/sql]
OR even if we want to know today’s users birthday !!
[sql]SELECT p FROM Person p WHERE p.birthday = CURRENT_DATE[/sql]
so in this case if our p.birthday
is a timestamp for some reasons we are in a big problem, because the previous case won’t work for us.
some documentations say “after a little search on the internet”, when you are passing the parameter “date” pass it with a costume setParameter method, so the EJB-QL knows how it will convert it to the native SQL daah !!!
[java]query.setParameter("date",calendar.getTime(), TemporalType.DATE)[/java]
alright we get it know it’s for the parameter but the problem is in the object property itself, isn’t ?
so we had to work around this case by passing two dates the first one is like this 2010-11-6:00:00:00 and the second is 2010-11-6:23:59:59
and use the between keyword. come on guys it’s a silly move.
[sql]SELECT p FROM Person p WHERE p.birthday BETWEEN date1 AND date2[/sql]
OK in this case you succeed with ignoring the HH:mm:ss bravo !!!
otherwise in the JBoss Hibernate you would easily do this by using the day function.
[sql]SELECT p FROM Person p WHERE p.birthday = day(current_date())[/sql] .
After all a good point is we can use Hibernate with our EJBs .
To Be Continued.