JPA SELECT 생성자 문법과 Aggregate 함수 학술

JSR 220 문서를 보면 아래 구절이 있다.

4.8.4. Aggregate Functions in the SELECT Clause

The Java type that is contained in the result of a query using an aggregate function is as follows:
  • COUNT returns Long.
  • MAX, MIN return the type of the state-field to which they are applied.
  • AVG returns Double.
  • SUM returns Long when applied to state-fields of integral types (other than BigInteger); Double
when applied to state-fields of floating point types; BigInteger when applied to state-fields of type BigInteger; and BigDecimal when applied to state-fields of type BigDecimal. If SUM, AVG, MAX, or MIN is used, and there are no values to which the aggregate function c

그래서 SELECT 생성자 문법 (select new full-qualified-classname) 써서 COUNT 결과 받는답시고,
int로 매개변수를 쓰면 Unable to locate appropriate constructor on class 예외만 받고 삽질하게 된다. -_-

결론은 long으로 하면 된다는 얘기.

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://xeraph.com/tb/4898210 [도움말]

덧글

  • 최종욱 2009/03/31 13:26 # 답글

    가만히 생각해보면 납득이 가는군요. 재미있습니다만, 문서화를 제대로 해놓지 않는다면 헷갈리기 쉽겠네요. ㅠㅠ
  • xeraph 2009/03/31 13:45 #

    웹에서 select new는 가끔 보이는데 타입 얘기는 진짜 안 나와요 (..)
댓글 입력 영역