-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Problems with Criteria.createCriteria & Criteria.createA
PostPosted: Sun Sep 07, 2003 10:39 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 11:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Thanks. All this Criteria stuff is brand-new.

This is why we do betas! :-)

HB-316

http://opensource.atlassian.com/project ... a?id=10460


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 07, 2003 11:49 pm 
Senior
Senior

Joined: Sun Aug 31, 2003 3:14 pm
Posts: 151
Location: Earth (at the moment)
Ah good, here I thought it was just me getting it wrong again. ;)

Just for the record, in case it is significant, setting the maps to new HashMap() instead of null didn't change the result.

Keep up the good work and by all means please let me know when you've got it figured out. I personally believe that using Criterias is definitely the way to go to seperate the layers cleanly. It was this feature that prompted me to use Hibernate in the first place.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 08, 2003 1:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is fixed in CVS, along with a bunch of other bugs in the new Criteria stuff. Whoah, there was a lot of Badness!

Anyway, we have new tests, so hopefully a lot more working state now.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.