-->
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.  [ 6 posts ] 
Author Message
 Post subject: Property Path Expressions and ASTQueryTranslatorFactory
PostPosted: Thu Nov 17, 2005 7:13 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
-----------------------------------------------------------------------------------

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents (relevant portions):
Code:
  <class name="com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl" table="contract">
    <id name="entityId" column="contract_id" unsaved-value="null">
      <generator class="sequence">
        <param name="sequence">contract_seq</param>
      </generator>
    </id>
    <many-to-one name="commodity" column="commodity_id" class="com.cbconstantini.fafnir.domain.commodity.CommodityImpl"/>               
    <property name="packingText" column="packing"/>
    <property name="type" column="contract_type" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.CommodityContractTypeEnumUserType"/>
    <many-to-one name="client" column="client_id" class="com.cbconstantini.fafnir.domain.client.ClientImpl"/>
    <property name="contractDate" column="contract_date" type="com.cbconstantini.core.hibernate3.YearMonthDayUserType"/>
    <component name="productQuantity" class="com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractProductQuantityImpl">
      <property name="quantityEstimate" column="quantity_estimate" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.QuantityEstimateEnumUserType"/>
      <property name="loadModifier" column="load_modifier" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.LoadModifierEnumUserType"/>     
      <component name="loads" class="com.cbconstantini.core.measurement.LoadUnitQuantityImpl">
        <many-to-one name="unit" column="load_unit_id" class="com.cbconstantini.core.measurement.LoadUnitImpl" access="field"/>
        <property name="amount" column="number_of_loads" access="field"/>   
      </component>
      <component name="weightQuantity" class="com.cbconstantini.core.measurement.WeightUnitQuantityImpl">
        <many-to-one name="unit" column="quantity_weight_unit_id" class="com.cbconstantini.core.measurement.WeightUnitImpl" access="field"/>
        <property name="amount" column="quantity_weight" access="field"/>
      </component>                         
      <component name="maxWeightQuantity" class="com.cbconstantini.core.measurement.WeightUnitQuantityImpl">
        <many-to-one name="unit" column="max_quantity_weight_unit_id" class="com.cbconstantini.core.measurement.WeightUnitImpl" access="field"/>
        <property name="amount" column="max_quantity_weight" access="field"/>
      </component>
      <component name="minWeightQuantity" class="com.cbconstantini.core.measurement.WeightUnitQuantityImpl">
        <many-to-one name="unit" column="min_quantity_weight_unit_id" class="com.cbconstantini.core.measurement.WeightUnitImpl" access="field"/>
        <property name="amount" column="min_quantity_weight" access="field"/>
      </component>     
    </component>             
    <many-to-one name="contactPerson" column="contact_id" class="com.cbconstantini.fafnir.domain.client.Contact"/>       
    <property name="deliveryCondition" column="delivery_condition" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.DeliveryConditionEnumUserType"/>
    <property name="fobModifier" column="fob_modifier" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.FobModifierEnumUserType"/>
    <many-to-one name="deliveryLocation" column="delivery_location_city_id" class="com.cbconstantini.fafnir.domain.location.City"/>
    <many-to-one name="paymentTerm" column="payment_term_id" class="com.cbconstantini.fafnir.domain.client.AbstractPaymentTerm"/>
    <property name="contractWeight" column="contract_weight"/>
    <many-to-one name="salesPerson" column="sales_person_user_id" class="com.cbconstantini.fafnir.domain.user.UserImpl"/>
    <many-to-one name="branch" column="contract_branch_id" class="com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractBranchImpl"/>
    <property name="remarks" column="remarks"/>
    <many-to-one name="broker" column="broker_client_id" class="com.cbconstantini.fafnir.domain.client.ClientImpl"/>   
    <property name="endorsed" column="endorsed"/>   
    <property name="endorsementTime" column="endorsement_timestamp" type="com.cbconstantini.core.hibernate3.DateTimeUserType"/>
    <property name="verificationTime" column="verification_timestamp" type="com.cbconstantini.core.hibernate3.DateTimeUserType"/>   
    <many-to-one name="verifiedBy" column="verified_by_user_id" class="com.cbconstantini.fafnir.domain.user.UserImpl"/>
    <many-to-one name="issuedToAddress" column="issued_to_address_id" class="com.cbconstantini.fafnir.domain.client.CommunicationAddress"/>
    <property name="timeIssued" column="issued_timestamp" type="com.cbconstantini.core.hibernate3.DateTimeUserType"/>   
    <property name="levyApplicable" column="levy_applicable"/>
    <property name="splitPayments" column="split_payments"/>
    <property name="commodityContractState" column="contract_state" type="com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractStateUserType"/>
    <component name="projectedProfit" class="com.cbconstantini.core.measurement.RateUnitQuantityImpl">
      <component name="unit" class="com.cbconstantini.core.measurement.RateUnitImpl">
        <many-to-one name="numerator" column="pp_numerator_unit_id" class="com.cbconstantini.core.measurement.AtomicUnitImpl" access="field"/>
        <many-to-one name="denominator" column="pp_denominator_unit_id" class="com.cbconstantini.core.measurement.AtomicUnitImpl" access="field"/>
      </component>
      <property name="amount" column="projected_profit_amount" access="field"/>
    </component>   
    <component name="projectedFreight" class="com.cbconstantini.core.measurement.RateUnitQuantityImpl">
      <component name="unit" class="com.cbconstantini.core.measurement.RateUnitImpl">
        <many-to-one name="numerator" column="pf_numerator_unit_id" class="com.cbconstantini.core.measurement.AtomicUnitImpl" access="field"/>
        <many-to-one name="denominator" column="pf_denominator_unit_id" class="com.cbconstantini.core.measurement.AtomicUnitImpl" access="field"/>
      </component>
      <property name="amount" column="projected_freight_amount" access="field"/>
    </component>           
    <set name="poNumbers" table="contract_po_number">
      <key column="contract_id"/>
      <element type="string" column="po_number"/>
    </set>
    <set name="shippingPositionsInternal" inverse="true" cascade="all-delete-orphan">
      <key column="contract_id"/>
      <one-to-many class="com.cbconstantini.fafnir.domain.productaccounting.contract.ContractShippingPositionImpl"/>
    </set>   
    <component name="priceAsCommodityContractPrice" class="com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractPriceImpl">
      <property name="pricingMethod" column="pricing_method" type="com.cbconstantini.fafnir.domain.productaccounting.contract.enum.PricingMethodTypeEnumUserType"/>
      <component name="price" class="com.cbconstantini.core.measurement.RateUnitQuantityImpl">
        <component name="unit" class="com.cbconstantini.core.measurement.RateUnitImpl">
          <many-to-one name="numerator" column="price_currency_id" class="com.cbconstantini.core.measurement.CurrencyImpl" access="field"/>
          <many-to-one name="denominator" column="price_weight_unit_id" class="com.cbconstantini.core.measurement.WeightUnitImpl" access="field"/>
        </component>
        <property name="amount" column="price_amount" access="field"/>
      </component>
      <component name="hedge" class="com.cbconstantini.core.measurement.MoneyImpl">
        <many-to-one name="unit" column="hedge_currency_id" class="com.cbconstantini.core.measurement.CurrencyImpl" access="field"/>
        <property name="amount" column="hedge_amount" access="field"/>
      </component>
    </component>   
  </class>


Code between sessionFactory.openSession() and session.close():
Code:
  public Collection getCommodityLoads(long commodityId, long clientId) throws DataAccessException
  {
    Object[] params = new Object[]{new Long(commodityId), new Long(clientId)};
    return getHibernateTemplate().find(
      "select distinct " +
      "contract.productQuantity.loads " +
      "from " +
      "CommodityContractImpl contract " +
      "where " +
      "contract.productQuantity.loads.unit is not null " +
      "and contract.productQuantity.loads.amount is not null " +
      "and contract.commodity = ? " +
      "and contract.client = ? ",
      params);
  }


Full stack trace of any exception that occurs:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: loads of: com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl [select distinct contract.productQuantity.loads from com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl contract where contract.productQuantity.loads.unit is not null and contract.productQuantity.loads.amount is not null and contract.commodity = ? and contract.client = ? ]; nested exception is org.hibernate.QueryException: could not resolve property: loads of: com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl [select distinct contract.productQuantity.loads from com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl contract where contract.productQuantity.loads.unit is not null and contract.productQuantity.loads.amount is not null and contract.commodity = ? and contract.client = ? ]
org.hibernate.QueryException: could not resolve property: loads of: com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl [select distinct contract.productQuantity.loads from com.cbconstantini.fafnir.domain.productaccounting.contract.CommodityContractImpl contract where contract.productQuantity.loads.unit is not null and contract.productQuantity.loads.amount is not null and contract.commodity = ? and contract.client = ? ]
   at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
   at org.hibernate.persister.entity.BasicEntityPersister.getSubclassPropertyTableNumber(BasicEntityPersister.java:1111)
   at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
   at org.hibernate.persister.entity.BasicEntityPersister.toColumns(BasicEntityPersister.java:1086)
   at org.hibernate.hql.ast.FromElementType.toColumns(FromElementType.java:298)
   at org.hibernate.hql.ast.FromElement.toColumns(FromElement.java:353)
   at org.hibernate.hql.ast.DotNode.getColumns(DotNode.java:91)
   at org.hibernate.hql.ast.DotNode.initText(DotNode.java:200)
   at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:181)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
   at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:83)
   at org.hibernate.hql.ast.DotNode.resolveSelectExpression(DotNode.java:534)
   at org.hibernate.hql.ast.HqlSqlWalker.resolveSelectExpression(HqlSqlWalker.java:474)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1527)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1467)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1041)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:380)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
   at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
   at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
   at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
   at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
   at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
   at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:748)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:310)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:739)
   at com.cbconstantini.fafnir.dao.HibernateCommodityContractDao.getCommodityLoads(HibernateCommodityContractDao.java:95)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:155)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
   at $Proxy1.getCommodityLoads(Unknown Source)
   at com.cbconstantini.fafnir.dao.HibernateCommodityContractDaoTest.testGetCommodityLoadsLongLong(HibernateCommodityContractDaoTest.java:423)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at junit.framework.TestCase.runTest(TestCase.java:154)
   at junit.framework.TestCase.runBare(TestCase.java:127)
   at junit.framework.TestResult$1.protect(TestResult.java:106)
   at junit.framework.TestResult.runProtected(TestResult.java:124)
   at junit.framework.TestResult.run(TestResult.java:109)
   at junit.framework.TestCase.run(TestCase.java:118)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database you are using:
DB2 8.1.3

The generated SQL (show_sql=true):
No SQL generated because HQL parsing failed.

Debug level Hibernate log excerpt:
Hmn. I haven't figured out how to enable that logging yet. I'll try to find out and post the log here.
-----------------------------------------------------------------------------------

I've just ported my application from Hibernate 2 to Hibernate 3. When I regression tested after the port, I noticed that the above HQL query failed with a "could not resolve property" QueryException (see stack trace above). Apparently, the query translator did not like the property path expression "contract.productQuantity.loads".

This exception ONLY occurs when I use ASTQueryTranslatorFactory for HQL query translation. If I switch to the ClassicQueryTranslatorFactory, the exception does NOT occur.

Interestingly, it seems that this exception only occurs when the property path expression is in the SELECT clause. If it is only in the WHERE clause, I do NOT get an exception. For example, if I change the SELECT from this "select distinct contract.productQuantity.loads" to this "select distinct contract.productQuantity" the query works, eventhough the WHERE clause uses the "contract.productQuantity.loads" property path expression multiple times.

For now, I can use the ClassicQueryTranslatorFactory, as advised in the Hibernate3 Migration Guide. However, I was wondering whether this is a bug and whether I should report it to JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 7:14 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
BTW, I searched JIRA and did NOT find a similar bug report.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:30 pm 
Newbie

Joined: Fri Nov 18, 2005 12:24 pm
Posts: 8
Cyboc, I think is bug. I do similar test and seems you are not only one who sees this one. Maybe you should try Hibernate 3.1rc3 now to see if fixes this?

Maybe Hibernate can comment on this one?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:35 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
Yeah I thought about trying 3.1rc3 but at the moment, it appears that the zip file is corrupted. This message seems to agree. Sigh...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 12:58 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
try cvs - i compile hibernate rc3 from cvs


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 18, 2005 2:49 pm 
Beginner
Beginner

Joined: Fri Apr 15, 2005 3:08 pm
Posts: 26
snpesnpe wrote:
try cvs - i compile hibernate rc3 from cvs


Thanks for the suggestion. I downloaded and built the jar.

When I ran my test of getCommodityLoads() with the new jar, it still fails with the same "could not resolve property" exception when using ASTQueryTranslatorFactory. In addition, some of my other tests are now failing. The exceptions are too numerous to put in this message. Perhaps I'll start a new topic.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.