For mysql I wrote a query like
SELECT * FROM mytable GROUP BY DATE(dateTimeField)
But i can\'t use the DATE()
function in JPQL
If You use Hibernate under the hood you can try :
Create your own dialect with custom function
public class CustomPostgresqlDialect extends PostgreSQLDialect {
public CustomPostgresqlDialect() {
super();
registerFunction("truncate_date",
new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "DATE(?1)" ));
}
}
Register Your dialect in persistence.xml
Use your function in JPQL.
select p from Post p group by truncate_date(p.dateCreated)