What is wrong with my code for nesting Criterias?
I first tried with the commented out lines and then I added the createAlias version and both generate the same type of error:
Quote:
net.sf.hibernate.QueryException: could not resolve property: prod.costFactors [null]
Code:
criteria = session.createCriteria(WorksheetHeader.class).add(
Expression.eq(WORKSHEET_ID, new Integer(worksheetID)));
criteria = criteria.createAlias("products", "prod");
criteria = criteria.createAlias("prod.costFactors", "costs");
criteria = criteria.createAlias("costs.calculatedTypeOptions", "calcTypes");
criteria = criteria.createAlias("costs.proratingTypeOptions", "proTypes");
// criteria = criteria.createCriteria("products");
// criteria = criteria.createCriteria("costFactors");
criteria = criteria.add(Expression.eq("calcTypes.language", language));
criteria = criteria.add(Expression.eq("proTypes.language", language));
criteria = criteria.createCriteria("costs.descriptions");
criteria = criteria.add(Expression.eq("language", language));
My classes look like this:
Code:
public class WorksheetHeader {
// other properties deleted for brevity
private Map products = null;
// ...
}
public class WorksheetProduct {
// other properties deleted for brevity
private Map costFactors = null;
// ...
}
public class WorksheetFactor {
// ...
}
And my mapping looks like this:
Code:
<!-- WorksheetProduct -->
<class name="com.fgl.ina.costestimation.WorksheetProduct" table="worksheet_product">
<id name="ID" type="integer" column="worksheet_product_id">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<!-- <many-to-one name="worksheetID" column="worksheet_id" not-null="true"/>-->
<property name="productID" column="ina_prod_id" type="long"/>
<property name="unitOfMeasureQuantity" column="uom_qty" type="float"/>
<map name="costFactors" table="worksheet_factor" lazy="false" cascade="all" order-by="worksheet_factor_id">
<key column="worksheet_product_id"/>
<index column="worksheet_factor_id" type="string"/>
<one-to-many class="com.fgl.ina.costestimation.WorksheetFactor"/>
</map>
</class>
<!-- WorksheetHeader -->
<class name="com.fgl.ina.costestimation.WorksheetHeader" table="worksheet_header">
<id name="worksheetID" type="integer" column="worksheet_id">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<property name="description" column="description" type="string"/>
<property name="vendor" column="vendor_no" type="string" not-null="true"/>
<property name="status" column="status" type="short" not-null="true"/>
<!-- <many-to-one name="status" class="com.fgl.ina.costestimation.lookups.WorksheetStatus"-->
<!-- column="status" update="false" insert="false" cascade="none" outer-join="true"/>-->
<property name="createdBy" column="created_by" type="string" not-null="true"/>
<property name="createdDate" column="created_date" type="timestamp" not-null="true"/>
<property name="revisedDate" column="last_revision_date" type="timestamp" not-null="true"/>
<property name="foreignStatus" column="foreign_status" type="short" not-null="true"/>
<!-- <bag name="validForeignStatuses" lazy="false" cascade="none" outer-join="true" order-by="foreign_status">-->
<!-- <many-to-many class="com.fgl.ina.costestimation.lookups.ForeignExchangeStatus" outer-join="true"/>-->
<!-- </bag> -->
<property name="foreignContractNo" column="foreign_contract_no" type="long" not-null="true"/>
<property name="comments" column="comments" type="string"/>
<map name="products" table="worksheet_product" lazy="false" cascade="all" order-by="worksheet_product_id">
<key column="worksheet_id"/>
<index column="worksheet_product_id" type="string"/>
<one-to-many class="com.fgl.ina.costestimation.WorksheetProduct"/>
</map>
</class>
<!-- WorksheetFactor -->
<class name="com.fgl.ina.costestimation.WorksheetFactor" table="worksheet_factor">
<id name="ID" type="integer" column="worksheet_factor_id">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<!-- <many-to-one name="worksheetProductID" column="worksheet_product_id" />-->
<property name="costFactorID" column="cost_factor_id" type="integer"/>
<property name="calculatedType" column="calculated_type" type="short"/>
<property name="costFactorValue" column="cost_factor_value" type="float"/>
<property name="foreignAmount" column="foreign_amount" type="float"/>
<property name="currencyType" column="currency_type" type="short"/>
<property name="exchangeRate" column="exchange_rate" type="float"/>
<property name="proratingType" column="prorating_type" type="short"/>
<many-to-one name="costFactor" class="com.fgl.ina.costestimation.CostFactor" insert="false" update="false"
cascade="none" column="cost_factor_id"/>
</class>
<!-- Cost Factor Description -->
<class name="com.fgl.ina.costestimation.CostFactorDescription" table="cost_factor_description" mutable="false">
<id name="costFactorID" type="integer" column="cost_factor_id">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<property name="language" column="locale" type="string"/>
<property name="description" column="description" type="string"/>
</class>
<!-- Cost Factor -->
<class name="com.fgl.ina.costestimation.CostFactor" table="cost_factor" mutable="false">
<id name="costFactorID" type="integer" column="cost_factor_id">
<generator class="net.sf.hibernate.id.IdentityGenerator"/>
</id>
<bag name="calculatedTypeOptions" lazy="false" cascade="none">
<key column="cost_factor_id"/>
<!-- <index column="allowable_type" type="integer"/>-->
<one-to-many class="com.fgl.ina.costestimation.lookups.CalculatedTypeLookup"/>
</bag>
<bag name="currencyTypeOptions" lazy="false" cascade="none">
<key column="cost_factor_id"/>
<!-- <index column="allowable_type" type="integer"/>-->
<one-to-many class="com.fgl.ina.costestimation.lookups.CurrencyTypeLookup"/>
</bag>
<bag name="proratingTypeOptions" lazy="false" cascade="none">
<key column="cost_factor_id"/>
<!-- <index column="allowable_type" type="integer"/>-->
<one-to-many class="com.fgl.ina.costestimation.lookups.ProratingTypeLookup"/>
</bag>
<map name="descriptions" lazy="false" cascade="none" table="cost_factor_descriptions">
<key column="cost_factor_id"/>
<index column="locale" type="string"/>
<one-to-many class="com.fgl.ina.costestimation.CostFactorDescription"/>
</map>
</class>
It seems to be able to create a nested Criteria on the first Map but not on the one inside of it.
Any suggestions?
Thank-you,
David