users@glassfish.java.net

Re: How to create EQL with aggregation function count, SELECT new DTO

From: <glassfish_at_javadesktop.org>
Date: Wed, 21 Feb 2007 06:20:34 PST

Hi Michael!

I have 2 EQL
1. it works
[b]SELECT res.id, res.firstname, res.surname, count(f)
FROM Person res JOIN res.friends f WHERE res.id=:id
GROUP BY res.id, res.firstname, res.surname[/b]

2. it does not work (this is commented in source code // why it does not work?)
[b]SELECT new dto.PersonDTO(res.id,res.firstname,res.surname, count(f))
FROM Person res JOIN res.friends f WHERE res.id=:id
GROUP BY res.id, res.firstname, res.surname[/b]

It throws exception:

Exception [TOPLINK-4002] (Oracle TopLink Essentials - 9.1 (Build b25)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') FROM test_person t0, test_person_friend t2, test_person t1 WHERE ((t0.id = 1) ' at line 1Error Code: 1064
Call:SELECT t0.id, t0.firstname, t0.surname, COUNT() FROM test_person t0, test_person_friend t2, test_person t1 WHERE ((t0.id = ?) AND ((t2.person_id = t0.id) AND (t1.id = t2.friend_id))) GROUP BY t0.id, t0.firstname, t0.surname

There should by [b]COUNT(t1.id)[/b] instead of [b]COUNT()[/b] in the generated SQL.

Fafi
[Message sent by forum member 'fafi' (fafi)]

http://forums.java.net/jive/thread.jspa?messageID=204630