I’m trying to translate a simple HQL to Criteria API, can anyone help me?
This is my HQL:
SELECT ch FROM Parent p JOIN p.childeren ch WHERE p.id = :id
As a result I get children. Important thing is there there is no relation from Child to Parent.
There is only relation in Parent to children like this:
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.ALL })
@JoinColumn(name="parent_id")
private List children;
How can I get the same results using criteria-api?
Only fetching an associated entity is a huge pain using the Criteria API. You would need sub-queries: