1

I have an SQL statement like this:

SELECT generatedresult,sum(size) as count  FROM table1_detail AS w WHERE date > '2011.06.01' AND w.l_date < '2011.06.02'  GROUP BY category ORDER BY count  desc ; 

Which returns:

generatedresult  |   count    
------------------+------------
                  | 3743040708
 Phrase1          |    1332377
 Phrase2          |          0
 Phrase3          |          0

When I write a resultset mapping for this query like this:

@Entity
@Stateless
@Cache(type = CacheType.NONE, alwaysRefresh=true, shared=false, expiry=1, size=0)
@Cacheable(false)
@SqlResultSetMappings({
    @SqlResultSetMapping(name = "ResultMapping",
    entities = {
        @EntityResult(entityClass = ResultMap.class,
        fields = {
            @FieldResult(name = "generatedresult", column = "generatedresult"),
            @FieldResult(name = "count", column = "count")
        })})
})

and use it in another class I got null result. Does anyone having any opinion about this issue?

lamostreta
  • 2,359
  • 7
  • 44
  • 61
  • I'll take a wild guess, since I don't really know all that much about resultset mapping. But it seems from your SQL that you select the sum AS count, but in the mapping you are actually looking for a column called count. – Nico Huysamen Jul 15 '11 at 07:09
  • Hi, that is how it is used in resultmapping. You can name a column in the sql as you like and than call it that way in the resultmapping. Anyway, thanks for your comment. – lamostreta Jul 21 '11 at 10:49

0 Answers0