Hibernate version: 3.05
When I create a simple projection using the Criteria, Hibernate generates an unnecessary from clause that covers the entire object graph while direct HQL produces appropriate SQL.
Am I doing something wrong when I setup my Criteria?
Criteria Projection:
Code:
Criteria criteria = session.createCriteria(BackgroundCheckOrder.class,"o");
criteria.setFetchMode("applicant",FetchMode.SELECT);
…..(for every many-to-one)
criteria.setProjection(Projections.property("o.primaryKey"));
select this_.pk as y0_
from orders.orders this_ left outer join product.products product2_ on this_.product_fk=product2_.pk left outer join scoring.first_steps firststep3_ on product2_.first_step_fk=firststep3_.pk left outer join questionnaire.questionsets questionse4_ on firststep3_.question_set_fk=questionse4_.pk left outer join questionnaire.questionset_versions questionse5_ on questionse4_.questionset_version_fk=questionse5_.pk left outer join questionnaire.questionsets questionse6_ on questionse5_.questionset_fk=questionse6_.pk left outer join company.companies company7_ on questionse6_.company_fk=company7_.pk left outer join billing.billing_configurations billingcon8_ on company7_.billing_configuration_fk=billingcon8_.pk left outer join company.companies company9_ on billingcon8_.company_fk=company9_.pk left outer join company.company_status_packages companysta10_ on company9_.company_status_package_fk=companysta10_.pk left outer join security.addresses address11_ on company9_.billing_address_fk=address11_.pk left outer join security.users user12_ on company9_.primary_contact_fk=user12_.pk left outer join company.companies company13_ on user12_.company_fk=company13_.pk left outer join security.addresses address14_ on company13_.address_fk=address14_.pk left outer join company.associations associatio15_ on company13_.association_fk=associatio15_.pk left outer join company.company_status_packages companysta16_ on associatio15_.default_company_status_package_fk=companysta16_.pk left outer join pricing.price_packages pricepacka17_ on associatio15_.default_price_package_fk=pricepacka17_.pk left outer join pricing.price_packages pricepacka18_ on company13_.price_package_fk=pricepacka18_.pk left outer join security.names name19_ on user12_.name_fk=name19_.pk left outer join security.addresses address20_ on user12_.address_fk=address20_.pk left outer join company.companies company21_ on user12_.base_company_fk=company21_.pk left outer join security.users user22_ on questionse6_.creator_fk=user22_.pk left outer join security.users user23_ on questionse5_.modifier_fk=user23_.pk left outer join company.companies company24_ on questionse5_.company_fk=company24_.pk left outer join background.background_check_packages background25_ on product2_.background_check_package_fk=background25_.pk left outer join pricing.product_prices price26_ on background25_.price_fk=price26_.pk left outer join product.products product27_ on price26_.product_fk=product27_.pk left outer join skills_assessments skillasses28_ on product27_.skill_assessment_fk=skillasses28_.pk left outer join background.background_checks background29_ on product27_.background_check_fk=background29_.pk left outer join questionnaire.questionsets questionse30_ on background29_.question_set_fk=questionse30_.pk left outer join security.permissions permission31_ on background29_.permission_fk=permission31_.pk left outer join company.companies company32_ on background25_.company_fk=company32_.pk where this_.order_type='BackgroundCheckOrder'
HQLCode:
Query query = session.createQuery("select o.primaryKey from BackgroundCheckOrder o");
select background0_.pk as col_0_0_ from orders.orders background0_ where background0_.order_type='BackgroundCheckOrder'