user manual
Chapter 17: EJB-QL and Data Access Support 181
Aggregate Functions in EJB-QL
<result-type-mapping>Local</result-type-mapping>
<ejb-ql>SELECT MAX(l.lineItemId) FROM Account AS a, IN
(a.accountLineItem) l WHERE l.accountId=?1</ejb-ql>
</query>
The following restrictions must be observed for aggregate functions:
■
Arguments to the SUM and AVG functions must be numeric (Integer, Byte,
Long, Short, Double, Float, and BigDecimal).
■
Arguments to the MAX and MIN functions must correspond to orderable
cmp-field types (numeric, string, character, and dates).
■
The path expression that forms the argument for the COUNT function can
terminate in either a cmp-field or a cmr-field. Application performance is
greatly enhanced when the COUNT function is used to determine the size
of a collection of cmr-fields.
Data Type Returns for Aggregate Functions
The following table shows the data types that can be arguments for the
various aggregate functions in EJB-QL selecting a single object, and what
data types will be returned.
An aggregate function that selects multiple objects returns a collection of the
wrappered Java data type that is returned.
Aggregate Function Argument data type Expected return type
MIN, MAX, SUM java.lang.Integer java.lang.Integer
AVG java.lang.Integer java.lang.Double
COUNT java.lang.Integer java.lang.Long
MIN, MAX, SUM java.lang.Integer java.lang.Integer
AVG java.lang.Integer java.lang.Double
COUNT java.lang.Integer java.lang.Long
MIN, MAX, SUM java.lang.Byte java.lang.Byte
AVG java.lang.Byte java.lang.Double
COUNT java.lang.Byte java.lang.Long
MIN, MAX, SUM java.lang.Byte java.lang.Byte
AVG java.lang.Byte java.lang.Double
COUNT java.lang.Byte java.lang.Long
MIN, MAX, SUM java.lang.Long java.lang.Long
AVG java.lang.Long java.lang.Double
COUNT java.lang.Long java.lang.Long
MIN, MAX, SUM java.lang.Long lonjava.lang.Long
AVG java.lang.Long java.lang.Double
COUNT java.lang.Long java.lang.Long
MIN, MAX, SUM java.lang.Short java.lang.Short
AVG java.lang.Short java.lang.Double










