开发者

How to define nulls for @Id field in Resultsetmapping?

I have a query like this:

SELECT sender, sum(size) AS size,COUNT(*) AS count FROM inmail 
WHERE  ( date > '2011.06.01' AND w.l_date < '2011.06.10' ) 
GROUP BY sender ORDER BY count DESC;

and its corresponding Entity class is this:

@Entity
@Stateless
@Cacheable(false)
@Cache(type = CacheType.NONE,alwaysRefresh=true, shared=false, expiry=1, size=0)
@SqlResultSetMappings({
    @SqlResultSetMapping(name = "ReportsResultMapping",
    entities = {
        @EntityResult(entityClass = ReportsResultMap.class,
        fields = {
            @FieldResult(name = "sender", column = "sender"),
            @FieldResult(name = "size", column = "size"),
            @FieldResult(name = "count", column = "count")
        })})
})
public class ReportsResultMap implements Serializable {

    @Id
    protected String sender;
    protected BigDecimal size;
    protected BigDecimal count;
...
}

Here comes the problem: The sender row in my table sometimes is null and query returns something like this:

sender             size         count
------------------+------------+------------
                  | 3743040708 |  69
 Phrase1          |    1332377 |  13
 Phrase2          |          0 |  1
 Phrase3          |          0 |  1 

this causes problem in my EJB mapping because sender field is defined as @Id and as a result server throws null pointer exception (saying that an ID field can not be null).

I am pretty sure this might be a general problem but I don't know how to phrase this problem to google it. Does anyone have a solution or workaround reccommendation for this problem? I tried to define si开发者_运维知识库ze as @Id but I know this is not a good solution.

Thanks in advance.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜