Hibernate Group通过查询 - 列不存在?

时间:2015-01-22 21:58:17

标签: hibernate

请帮我解决这个hibernate查询:

我有班级客户,项目和类别;而我正试图找到它的总和 来自客户的项目,按类别分组

hql.append("Select sum(amount), category From Item ")
        .append(" Where owner=:owner")
        .append(" And month(createOn)=:month")
        .append(" And year(createOn)=:year");

    hql.append(" group by category");

    Query query = getQuery(hql.toString())
                        .setParameter("owner", owner)
                        .setParameter("month", month)
                        .setParameter("year", year)
                        ;


    List<Object[]> resultList = query.list();
    List<ItemHolder> itemHolderList = new ArrayList<ItemHolder>();

    for(Object[] obj : resultList) {
        ItemHolder bo = ItemHolder.getInstance();
        bo.setAmount((BigDecimal) obj[0]);
        bo.setCategory((Category)obj[1]);
        itemHolderList.add(bo);

    }

    return itemHolderList;

这是我的项目类:

@Column(name="AMOUNT")
private BigDecimal amount;

@ManyToOne
@JoinColumn(name="OWNER_ID")
private Customer owner;


@ManyToOne(fetch=FetchType.EAGER)
@JoinColumn(name="CAT_ID")
private Category category;


@Temporal(TemporalType.DATE)
@Column(name="CREATEON")
private Date createOn;

这是我得到的错误:

ERROR: org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ERROR: column "owner" does not exist

0 个答案:

没有答案