Hibernate Criteria: Return different entity type than rooted entity?

Posted by Gilean on Stack Overflow See other posts from Stack Overflow or by Gilean
Published on 2010-04-07T04:03:57Z Indexed on 2010/04/07 4:33 UTC
Read the original article Hit count: 224

Filed under:
|
|

I have entities similar to:

ProductLine: id, name
ProductLineContents: content_id, product_line_id
Content: id, text, updated_time

What I'd like to do is: for each product line, get the latest content (so if theres two content entries associated to one product line, the latest updated_time is rturned, and if one content item is associated to two product lines, it is returned twice). Something similar to:

select content.* from productline 
inner join productlinecontents
inner join content;

However I can't seem to figure out how to have Hibernate Criteria return a different entity than the original one it was created with. So if I wanted to start the criteria at the product line with createCriteria(ProductLine.class) along with the proper joins, then it only returns ProductLine objects, but I need Content objects.

What's the best way to accomplish this?

The actual data model is much more complex and can't be modified

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about criteria