I can't make a inner join between two tables in hibernate hql query

匆匆过客 提交于 2019-12-06 04:47:35

In HQL, you use entities, not tables. And entities are linked together by associations (OneToOne, OneToMany, etc.) Joins can anly be done between associated entities.

For example, if you have a ManyToOne association between Product and Provider, the HQL query is:

select p from Product p inner join p.provider provider where ...

The on clause is unnecessary, because Hibernate knows from the mapping of the ManyToOne association that a Product is associated with its provider using the product.id_provider foreign key to the provider.id_provider primary key.

All of this is very well explained, with lots of examples, in the Hibernate documentation.

Sarah Phillips

If an association (e.g. OneToMany mapping) does not exist and you need an inner join then use the old cross join notation.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!