本机查询不映射计数(*)变量

时间:2014-07-18 06:46:52

标签: java mysql jpa nativequery

我正在研究Jpa Native查询,

我希望我所有的人都发送它,但这是我的查询

select id,status,COUNT(*) as count from tb_abc where sender_id=?1 group by status

但问题是当我在Mysql上运行它然后它会正常运行但是当我将使用java代码运行,即本机查询然后count返回null或0 ..

这是我的课程,我有来自查询的地图

此原生查询

@Repository 公共课PatientAppointmentNativeDao {

@PersistenceContext
private EntityManager em;

public List<TableAbc> get(Long senderId) {

    @SuppressWarnings("unchecked")
    List<TableAbc> resultData = (List<TableAbc>) em
            .createNativeQuery(
                    "select *,COUNT(*) as count from tb_abc where sender_id=?1 group by status",
                    com.abc.TableAbc.class)
            .setParameter(1, senderId)
            .getResultList();

    return resultData;
}

}

和TableABC类如下:

公共类PatientAppointment {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;



@ManyToOne
private Sender sender;

private Integer status;


@Transient
private int countTotal;

public int getCountTotal() {
    return countTotal;
}

public void setCountTotal(int countTotal) {
    this.countTotal = countTotal;
}

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}




public Integer getStatus() {
    return status;
}

public void setStatus(Integer status) {
    this.status = status;
}

}

请帮帮我......

0 个答案:

没有答案