我想要做SELECT e FROM Pedidos e WHERE e.diaPedido = :diaPedido AND e.horaPedido = :horaPedido
。
當我寫參數使用query.setParameter("diaPedido", fechaEscogida, TemporalTipe.DATE)
和query.setParameter("horaPedido", horaEscogida, TemporalTipe.TIME)
,但我不知道爲什麼第二個篩選器Temporal.TIME
不工作,因爲仍然比較像TIMESTAMP。
我使用eclipseLink 2.3.0和javax.persistence 2.0.1。
diaPedido and horaPedido都是oracle數據庫中的Date。Query.setparameter using TemporalTipe.Time
2
A
回答
3
如果您只想比較TIMESTAMP列的時間部分,則需要使用數據庫函數。
在EclipseLink(> = 2.4)中,可以使用EXTRACT或CAST或FUNCTION/FUNC運算符來調用數據庫函數。
見, http://java-persistence-performance.blogspot.com/2012/05/jpql-vs-sql-have-both-with-eclipselink.html
+0
當我使用** CAST **給我錯誤,因爲'CAST('horaPedido',AS TIME)'說我** ** horaPedido **不是** NUMBER **。以及我如何提取** TIME **'EXTRACT(TIME,e.horaPedido)' –
相關問題
- 1. jpql中的TemporalTipe.Time參數
- 2. Javascript summming arrays using using d3.nest()
- 3. using @using(html.beginform())JavaScript is Disabled?
- 4. using setChildIndex();
- 5. Using Intent.putextra
- 6. using System.Reflection
- 7. using requestAnimationFrame
- 8. using System.Windows.Forms.Datagrid
- 9. using num.toFixed();
- 10. INSERT INTO using WHERE
- 11. url dispatch using backbone.js
- 12. @using block before @ Html.BeginForm
- 13. sencha-touch using ActionSheet
- 14. xquery error:while using clause
- 15. using System.Linq;在.NET
- 16. MemoryError using json.dumps()
- 17. Microsoft Translator Using PHP
- 18. Ab-using languages
- 19. IndexError using python-ntlm
- 20. NullPointer.Exception PopupWindow.getMaxAvailableHeight using ListPopupWindow
- 21. UniqueEntity using Doctrine 2
- 22. NullReferenceException while using linq
- 23. Google Picker using Scala.js
- 24. Window.showModalDialog()using javascript
- 25. radix select using cuda
- 26. LEFT JOIN using OR
- 27. Polymer:Help using dom-if
- 28. Arrayoutofboundsexception using setspan
- 29. Curriculum using Scheme
- 30. android class using viewflipper
TemporalType.TIME力量JPA使用您的java.util.Date,就好像它是一個java.sql.Time中。你沒有提到你遇到的問題,但時間沒有日期信息,只有時間部分。如果在日期對象中有日期信息,則使用與DATE類型相等的時間將不起作用。嘗試查看數據庫中的內容以及要發佈的內容 - 打開EclipseLink日誌記錄以正確打印SQL。機會是你應該使用TemporalType.Date。 – Chris
但我只想比較小時:分鐘:秒不是全部日期。 –