| 
					
						 Hi,
 
 I noticed something strange using DetachedCriteria with subqueries: Listing the outer DetachedCriteria produces a NPE unless the inner DetachedCriteria is listed first.
 
 This kind of defeats to purpose of DetachedCriteria for me, because I need access to the session while assembling the DetachedCriteria.
 
 Is anyone aware of another workaround? An even better solution would be a join inside the employees subquery, but that's currently not possible AFAIK.
 
 Any ideas?
 
 Thanks, Dan.
 
 
 Hibernate version: 3.0.5 
 Code between sessionFactory.openSession() and session.close():
 Session session = // ...
 
 DetachedCriteria addresses = DetachedCriteria.forClass(Address.class);
 addresses.add(Restrictions.eq("city", "chicago"));
 addresses.setProjection(Projections.property("id"));
 
 DetachedCriteria employees = DetachedCriteria.forClass(Employee.class);
 employees.add(Property.forName("address").in(addresses));
 employees.setProjection(Projections.property("department"));
 
 DetachedCriteria departments = DetachedCriteria.forClass(Department.class);
 departments.add(Property.forName("id").in(employees));
 
 Criteria crit = departments.getExecutableCriteria(session);
 
 // unless this method is called before crit.list(), // Hibernate fails with a NPE, see below
 employees.getExecutableCriteria(session).list();
 
 List result = crit.list();
 
 Full stack trace of any exception that occurs:
 java.lang.NullPointerException
 	at org.hibernate.criterion.SubqueryExpression.getTypedValues(SubqueryExpression.java:80)
 	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:231)
 	at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:55)
 	at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:314)
 	at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
 	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1303)
 	at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:300)
 	...
 
 Database schema:
 TABLE DEPARTMENT
 -ID
 -NAME
 
 TABLE EMPLOYEE
 -ID
 -NAME
 -DEPT_ID
 -ADDRESS_ID
 
 TABLE ADDRESS
 -ID
 -STREET
 -CITY 
					
  
						
					 |