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

View: New views
2 Messages — Rating Filter:   Alert me  

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

by Saturon :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

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=@EntityResult(entityClass=Foo.class,fields=@FieldResult(name="id", column="id")),
    columns={@ColumnResult(name="countAll"),@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
---------------------------------------------------------------------------------


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

by Gordon Yorke-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

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

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=@EntityResult(entityClass=Foo.class,fields=@FieldResult(name="id", column="id")),
    columns={@ColumnResult(name="countAll"),@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
---------------------------------------------------------------------------------