开发者

How to use Hibernate Criteria for joining two tables with OneToMany relation

I have two tables for which I can't implement mapping @OneToMany in their entities unless I have a circle dependency. I want to create a Hibernate Criteria so that I'd be able to join this tables on ids' fields plus a restriction. However, I have a sql query which gives me a result I'm looking for, I failed to understand how to implement the criteria.

Tables which have a shared id:

|  Table A  | Table B |
|id         | id      |
|languageId | code    |
|comment    |         |

SQL query:

select a.id, a.languageId, a.comment, b.code from TableA a join TableB b on a.id=b.id

Could anybody help me to write the 开发者_如何学CHibernate Criteria?

Thank you in advance, L.


You cannot do it - Hibernate Criteria doesn't support join on arbitrary conditions.

You have to use HQL query (it doesn't support JOIN syntax with arbitrary condition too, but you can use old-style syntax):

SELECT a, b FROM A a, B b WHERE a.id = b.id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜