persistence@glassfish.java.net

Re: SqlResultSetMapping entity and scalar types with toplink-essentials does not work for me

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 08 Sep 2009 14:13:05 -0300

This is generally an issue with case. Try using COUNTALL and COUNTSOME
for @ColumnResult name.
--Gordon

saturon wrote:
>
> Hi there,
>
> I cannot get SqlResultSetMapping with 2 scalar and 1 entity type to
> work correctly. The scalar types somehow do not get mapped to the
> result, the entity type does. Executing the query on a psql console
> returns always a positive number for the counts, via JPA scalar types
> are null.
>
> Setup:
> Postgres 8.3
> Glassfish 2.2 with toplink-essentials that came packed within
> JPA
>
> Entity:
> @SqlResultSetMapping(name="myCount",
>
> entities=_at_EntityResult(entityClass=Foo.class,fields=_at_FieldResult(name="id",
> column="id")),
>
> columns={_at_ColumnResult(name="countAll"),_at_ColumnResult(name="countSome")})
> @Entity
> @Table(name = "my_foo")
> public class Foo implements Serializable {
> ...
>
> Query:
> String sql = "select f.id,count(a.id) as countAll, count(b.id) as
> countSome from my_foo f, ....";
> List<Object[]> arr =
> service.createNativeQuery(sql,"myCount").getResultList();
>
> Expected Result: arr[0]: [ f: Foo, <number>, <number> ]
>
> Actual Result: arr[0]: [ f:Foo, null, null ]
>
>
> Thanks for pointers.
>
>
> Ben
> ---------------------------------------------------------------------------------
>
>