berimbolo
berimbolo

Reputation: 3829

hibernate QuerySyntaxException - Field is not mapped

I am getting a QuerySyntaxException trying to run a HQL query against 2 tables:

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

The exception is:

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

My entities are set up so I thought everything was 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);

I want to select all products with a category of 'x' and a product type of 'y'.

A product has a set of categories and it also has a single type, although a type can apply to many products.

Can anyone see what is wrong with my query?

Upvotes: 1

Views: 922

Answers (1)

Daniel Boncioaga
Daniel Boncioaga

Reputation: 348

I guess you are missing join keyword before p.productType t.

So, the query should be:

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

Later edit: removed comma after p.categories c

Upvotes: 2

Related Questions