我正在处理 Jpa Native 查询,
我希望我的所有发送都包含在内,但这是我的查询
select id,status,COUNT(*) as count from tb_abc where sender_id=?1 group by status
但问题是当我将在 Mysql 上运行它时它会运行良好但是当我将使用 java 代码运行时,即本机查询然后计数返回 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;
}
}
请帮我 ...