I wanna do SELECT e FROM Pedidos e WHERE e.diaPedido = :diaPedido AND e.horaPedido = :horaPedido
.
When I write parameters use query.setParameter("diaPedido", fechaEscogida, TemporalTipe.DATE)
and query.setParameter("horaPedido", horaEscogida, TemporalTipe.TIME)
but i don´t know why second filter Temporal.TIME
doesn´t work because still compare like TIMESTAMP.
I use eclipseLink 2.3.0 and javax.persistence 2.0.1.
diaPedido and horaPedido are both Date in oracle database.
Asked
Active
Viewed 563 times
2

Mathew Rock
- 989
- 2
- 14
- 32
-
TemporalType.TIME forces JPA to use your java.util.Date as if it were a java.sql.Time. You haven't mentioned the issue you are getting, but Time doesn't have date information, only the time portion. Using your Time with equality to the DATE type will not work if there is date information in the date object. Try looking at what is in the database and what you are issuing to see for yourself - turn on EclipseLink logging to fine to get the SQL printed off. Chances are you should be using TemporalType.Date. – Chris Jul 12 '13 at 13:20
-
But I just wanna compare hours:minutes:seconds not all Date. – Mathew Rock Jul 12 '13 at 22:48
1 Answers
3
If you want to just compare the time portion of a TIMESTAMP column, you need to use a database function.
In EclipseLink (>=2.4) you can use EXTRACT or CAST, or the FUNCTION/FUNC operator to call a database function.
See, http://java-persistence-performance.blogspot.com/2012/05/jpql-vs-sql-have-both-with-eclipselink.html

James
- 17,965
- 11
- 91
- 146
-
When I use **CAST** give me error because `CAST('horaPedido', AS TIME)` say me that **horaPedido** is not a **NUMBER**. And How I can extract **TIME** `EXTRACT(TIME, e.horaPedido)` – Mathew Rock Jul 22 '13 at 12:49