开发者

How to translate sql to hibernate criteria query

How do i translate this pseudo-query into a hibernat开发者_开发技巧e criteria query?

Given itemID=123, item table has a foreign key reference to category table (catgeoryId), i want to return category coresp to the item with id 123...

select cats.category from Item as item inner join category as cats where item.id = itemID


Why would you want to do a Criteria? Given that you know the id, you can just load your Item and inspect it's Category field.

The goal of Hibernate is to make database programming simpler for OOP programmers, not more convoluted.


Criteria isn't the best match for this particular need. Criteria are most useful when you're building dynamic queries, in my experience.

If I understand your domain correctly, this is pretty simply expressed in HQL:

select item.category from Item item where item.id = :itemId
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜