views:

498

answers:

2

Can I perform a Criteria query with Sub-Select AND Left-Outer join?

For example, I have A 1-many B 1-many C.

With Criteria.createAlias ("b", "b", Criteria.LEFT_JOIN) I can perform Left Outer join.

With Criteria.setFetchMode ("b", org.hibernate.FetchMode.DEFAULT) I can perform Join with the default fetching strategy. I assume that having set @org.hibernate.annotations.FetchMode.SUBSELECT in both A.B and B.C is enough (is it?).

Question 1: Why does org.hibernate.FetchMode not have SUBSELECT option, whereas the org.hibernate.annotations.FetchMode does?

Question 2: Can I perform a Criteria query with Sub-Select AND Left-Outer join?

A: 

org.hibernate.FetchMode has the same option under a different name, SELECT.

Péter Török
A: 

Criteria and org.hibernate.FetchMode.SELECT does nothing. The only option for Criteria is org.hibernate.FetchMode.JOIN. I do lazy initialization for Criteria results manually:

for (Entity e : result) {
 Hibernate.initizalize(e.getProperty());
}
xmedeko