Hello,
I think my question is simple I have this objects (simplified):
Code:
class A{
   private Set bSet; // Object of Type B
   ...
}
class B{
   ...
}
The user can select 0..n B's of all existing B's and he wants to have all A's which have min one of the selected B's.
So, I implemented it in this way:
Code:
    public A[] searchAs(B[] selectedBs)
        Long[]  selectedBsIds = new Long[selectedBs.length];
                    
        for (int i = 0; i < selectedBs.length; i++) {
            selectedBsIds[i] = selectedBs[i].getId();                    
        }
    
        Session session = getSession();
        Criteria aCriteria = session.createCriteria(A.class);                        
        Criteria bCriteria = aCriteria.createCriteria("bSet");                
        bCriteria.add(Expression.in("id", selectedBsIds));          
        aCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return (A[]) aCriteria.list().toArray(new A[0]);        
        
    }
But I don't like the for(){} and the handling with the id's. Is there a way to do it directly, like:
Code:
    public A[] searchAs(B[] selectedBs)
    
        Session session = getSession();
        Criteria aCriteria = session.createCriteria(A.class);                        
        Criteria bCriteria = aCriteria.createCriteria("bSet");                
        bCriteria.add(Expression.in(selectedBs)));          
        aCriteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
        return (A[]) aCriteria.list().toArray(new A[0]);        
        
    }
Thanks and Regards
Oliver