2015-07-13 70 views
1

我得到一个QuerySyntaxException试图对2台运行HQL查询:休眠QuerySyntaxException - 现场没有映射

select p from ProductEntity p join p.categories c, p.productType t where c.name = :category and t.name = :type 

唯一的例外是:

org.hibernate.hql.internal.ast.QuerySyntaxException: p.productType is not mapped 

我的实体成立,所以我认为一切都被映射:

Product Entity: 

@ManyToOne(fetch = FetchType.LAZY) 
@JoinColumn(name = "PRODUCT_TYPE_ID", nullable = false) 
private ProductTypeEntity productType; 

Product Type Entity: 

@OneToMany(fetch = FetchType.LAZY, mappedBy = "productType") 
private Set<ProductEntity> products = new HashSet<ProductEntity>(0); 

我想选择一个类别o f'x'和产品类型'y'。

产品有一组类别,它也有单一类型,尽管某种类型可以应用于许多产品。

任何人都可以看到我的查询有什么问题吗?

回答

2

我想你在p.productType t之前缺少join关键字。

因此,查询应该是:

select p from ProductEntity p join p.categories c join p.productType t where c.name = :category and t.name = :type 

后来编辑:删除逗号后p.categories c

+0

我已经试过了:org.hibernate.hql.internal.ast.QuerySyntaxException:意外的标记:加盟在第1行第94列 – berimbolo

+0

哦,请在c后删除'逗号' –

+0

谢谢,我不能相信它只是逗号:( – berimbolo