Hello,
It's not object but tables, JPA return a list of tables :
[id,name,count]
[id,name,count]
...
On 25 nov, 14:53, sun <
goo...@suncom.de> wrote:
> Hi, I am new to JPA and Play and if this is a plain JPA question
> excuse me please and send me away, I am unsure about this.
>
> I want to know how many Ads are in a Category and try to use this
> query:
>
> System.out.println("noOfCats: " +
> JPA.em().createNativeQuery("select count(id) from
> MainCategory").getSingleResult());
> System.out.println("noOfAds: " +
> JPA.em().createNativeQuery("select count(id) from
> Ad").getSingleResult());
> Query query = JPA.em().createNativeQuery("select
cat.id,
cat.name,
> count(
ad.id) from MainCategory as cat "
> + "join Ad as ad group by
cat.id,
cat.name");
> List res = query.getResultList();
> System.out.println("size:" + res.size());
> for(int i=0; i<res.size(); i++) {
> System.out.println(res.get(0));
> }
>
> This is written to the console:
>
> 15:59:37,214 DEBUG ~ select count(id) from MainCategory
> noOfCats: 7
> 15:59:37,214 DEBUG ~ select count(id) from Ad
> noOfAds: 1
> 15:59:37,214 DEBUG ~ select
cat.id,
cat.name, count(
ad.id) from
> MainCategory as
> cat join Ad as ad group by
cat.id,
cat.name
> size:7
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
> [Ljava.lang.Object;@1cf8595
>
> What I get are 7 results, one for each category, seems correct. The
> problem is I get Objects, I do not get Integers (id and count(id) and
> String (name)) but plain Objects - I have no idea what to do with
> them.
>
> I am using plain old JDBC now for my query and it works fine, but I
> have the feeling it should be possible to query aggregate functions
> with JPA too.