views:

254

answers:

1

Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an entity with a java.util.Date field indicating when the row was created. Is it possible to perform a query using JPQL and include date arithmetic on that field? For example, can I perform a COUNT(*) of rows and then GROUP BY the month in that field? Can I perform other functions, such as only return the month or year from that field in a query?

+1  A: 

HQL does have date expressions like second(...), minute(...), hour(...), day(...), month(...), and year(...) but standard JPQL doesn't have such functions.

Pascal Thivent
Is it possible to use HQL in conjunction with JPQL to get the results I need? Will HQL return the same entities as they are, or do I need to add additional annotations, etc. to them?
Shadowman
@Shadowman: Yes it is and you don't need specific annotations to use them. It's just that your query won't be portable (there is no guarantee that another provider will support these functions).
Pascal Thivent