在我的项目表中,我有一个枚举列来描述该项目的状态:
@Enumerated(EnumType.STRING)
@Column(name="status")
private ItemStatus status;
然后,当我将商品添加到购物车时,我想用此查询列出购物车中的所有商品:
select i.* from item as i inner joint cart as c on i.item_id = c.item_id
where c.owner_id=:owner_id group by i.item_id
上面的结果按照我的预期返回。不过,我还希望获得有关该项目所有者的更多详细信息,以便将查询更改为:
select i.*, u.* from item as i inner join cart as c on i.item_id = c.item_id
inner join customer as u on i.owner_id = u.customer_id
where c.owner_id = :owner_id group by i.item_id, u.customer_id
SQLQuery query = session.createSQLQuery(queryname);
List<Object[]> result = query.addEntity(Item.class)
.addEntity(Customer.class)
.setParameter("owner_id", owner_id)
.list();
使用第二个查询,我在状态列上获得了枚举类的未知名称值。我想知道为什么第一个查询有例外但第二个查询有例外。在hibernate中获取枚举列的正确方法是什么?
这是我的枚举类
public enum ItemStatus {
ACTIVE, UNAVAILABLE;
}
答案 0 :(得分:0)
你不应该也添加Cart实体吗?
List<Object[]> result = query.addEntity(Item.class)
.addEntity(Cart.class)
.addEntity(Customer.class)
.setParameter("owner_id", owner_id)
.list();