public Collection ejbFindByComplex(Integer complexID) throws FinderException { Table category = new Table(this, "c"); Table type = new Table(ApartmentType.class, "t"); Table apartment = new Table(Apartment.class, "a"); Table floor = new Table(Floor.class, "f"); Table building = new Table(Building.class, "b"); SelectQuery query = new SelectQuery(category); query.setAsDistinct(true); query.addColumn(new WildCardColumn(category)); try { query.addJoin(type, category); query.addJoin(apartment, type); query.addJoin(apartment, floor); query.addJoin(floor, building); } catch (IDORelationshipException e) { throw new FinderException(e.getMessage()); } query.addCriteria( new MatchCriteria( new Column(building, BuildingBMPBean.BU_COMPLEX_ID), MatchCriteria.EQUALS, complexID.intValue())); query.addOrder(category, this.getIDColumnName(), true); return idoFindPKsBySQL(query.toString()); }