我尝试对一列求和,但出现空指针异常,我不知道自己做错了什么。
ChartVentaVendedores chart = new ChartVentaVendedores();
Criteria facturas = getSession().createCriteria(Factura.class);
facturas.add(Restrictions.like("estado", "CONFIRMADO"));
facturas.add(Restrictions.between("fechaCreacion", fromDate, toDate));
Criteria vendedorFactura = facturas.createCriteria("idVendedor");
vendedorFactura.add(Restrictions.eq("idUsuario", idVendedor));
facturas.setProjection(Projections.sum("total"));
Long counter = (Long) facturas.uniqueResult();
int value = counter.intValue();
chart.setValue(counter.intValue());
chart.setDate(fromDate);
即使我没有进行连接,我仍然得到 null
。
我试图将 Long counter = (Long) facturas.uniqueResult();
的类型更改为 BigInteger
但我仍然遇到相同的错误。
我的类(class):
@Entity
@Table(name = "factura")
public class Factura implements Serializable {
private int idFactura;
private Cliente cliente;
private String estado;
private Usuarios idVendedor;
private Date fechaCreacion;
private Date fechaModificacion;
private Integer usuarioCreacion;
private Integer usuarioModificacion;
private BigInteger total;
private String tipoFactura;
....
}
最佳答案
我认为,您的 Projections.sum("total")
不能对 BigInteger
求和,因为它没有自动装箱。
如果可以,请尝试将 BigInteger
更改为 Integer
或 Long
。
关于java - 标准总和投影,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35972808/