eclipselink - spring data jpa max aggregate function in where clause -
i have error query
@repository public interface definedabsencerepository extends jparepository<definedabsence, long>, jpaspecificationexecutor<definedabsence> { @query("select da defined_absence da da.length=?1 , max (da.from, ?2) < min (da.to , ?3) " ) list<definedabsence> getlongdefinedabsencewithinperiod( absencelength length, localdatetime from, localdatetime to); }`
and class
public class definedabsence extends basebean { public static enum absencejustification { justified, unjustified } private localdatetime from; private localdatetime to; private absencelength length; private string description; //geter()+setter() }
i use converter joda time
the error generated caused by: exception [eclipselink-0] (eclipse persistence services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.jpqlexception exception description: syntax error parsing [select da defined_absence da da.length=?1 , max (da.from, ?2) < min (da.to , ?3) ]. [59, 70] right expression not valid expression. [72, 95] query contains malformed ending.
you confusing max(a, b)
function programming languages, compares 2 values , returns greater one, , max(expression)
aggregation function sql, finds maximum value result rows (possibly grouped) single expression.
to use max(a, b)
, min(a, b)
in sql, have use case
:
select da defined_absence da da.length = ?1 , (case when da.from > ?2 da.from else ?2) < (case when da.to < ?3 da.to else ?3)
Comments
Post a Comment