如果为null,则Hibernate在select上设置默认值

时间:2015-02-06 02:29:45

标签: java hibernate jpa

如何设置

的默认值
select sum(i.price), i.category from item as i where i.customer=:customer group by i.category.

因此,如果客户创建他们的类别并购买类别中的一些项目,我的查询将运行良好。但是,如果客户只是创建其类别而不购买任何项目,则不会返回该数据。如何返回类别并显示0?

我试图在getter中获取它,但它不能正常工作:

@Column(name="price", columnDefinition="BigDecimal default 0")
public BigDecimal getPrice;
private BigDecimal price;

1 个答案:

答案 0 :(得分:0)

你可以使用:

@Column(name="price") private BigDecimal getPrice = 0;

希望这可能有所帮助。