I have these twos sql scripts, and i’m getting some problems to perform
the translation in hql, to be used in a Query from JPA:
SELECT f.idprovider, pe.name from provider f
inner join person pe
on(f.idperson = pe.idperson)
inner join product_provider pf
on(f.idprovider = pf.idprovider)
inner join product p
on(pf.idproduct = p.idproduct)
inner join item i
on(p.idproduct = i.idproduct)
where i.iditem = 1
SELECT f.idprovider, pe.name, pe.cnpjf from product_provider pf
inner join provider f
on(pf.idprovider = f.idprovider)
inner join coliseusys.person pe
on(f.idperson = pe.idperson)
inner join product p
on(pf.idproduct = p.idproduct)
where p.idproduct = (select p2.idproduct from item i inner join product p2
on(i.idproduct = p2.idproduct) where i.iditem = 1)
these sqls do the same thing, and i’ve tried a lot do take the hql from any of it, without results.
the mapping in hibernate is ok.
any idea?
The translation is immediate :
This is assuming that
If that’s not the case, then describe your mapping, because doing HQL without knowing the entities is impossible. It’s like doing SQL without knowing the tables.
You should read http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#queryhql. It has lots of examples of HQL queries and explain how they work in great details.