-->
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.  [ 2 posts ] 
Author Message
 Post subject: select column of composite key
PostPosted: Fri Sep 30, 2005 5:31 pm 
Newbie

Joined: Fri Sep 30, 2005 5:10 pm
Posts: 3
I'm using Hibernate 3.0 with Spring layered on top of it. DB2. I have a legacy table that needed to have a composite class defined for the key. Now I want to select one of the columns of the composite key in a query but getting QueryException saying could not resolve property. I've tried to include relevant snippets of all the code and the exception. Any ideas whats going on?

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.picct.model.Cm3rStakehldr"
    table="pg#12.CM3R_STAKEHLDR"
   lazy="false"
    mutable="false"
>
    <meta attribute="implement-equals" inherit="false">true</meta>
      
         <composite-id
        name="Cm3rStakehldrCK"
        class="com.picct.model.Cm3rStakehldrCK" >
       
       <key-property
            name="number"
            column="NUMBER"
            type="java.lang.String"
            length="20"
        />
        <key-property
            name="recordNumber"
            column="RECORD_NUMBER"
            type="java.lang.Integer"
            length="10"
        />
       
       </composite-id>



Code:
/** @author Hibernate CodeGenerator */
public class Cm3rStakehldr implements Serializable {
   
   /**
    *
    */
   private static final long serialVersionUID = -2029696508334159560L;

   /** composite key */
   private Cm3rStakehldrCK cm3rStakehldrCK;
   




Code:
public class Cm3rStakehldrCK implements Serializable {
   
   /**
    *
    */
   private static final long serialVersionUID = 5443599309643197673L;

   /** identifier field */
    private String number;

    /** identifier field */
    private Integer recordNumber;




Code:
//       build up query
      StringBuffer sb = new StringBuffer();
      sb.append("select cm3rStakehldr.cm3rStakehldrCK.number from Cm3rStakehldr cm3rStakehldr where cm3rStakehldr.wcmStkhrGrpNme in (");
      sb.append("'" + contact + "', ");
      
      Iterator i = group.iterator();
   
      while (i.hasNext()) {
         sb.append("'" + i.next() + "', " );
      }
      sb.delete(sb.length() - 2, sb.length());
      sb.append(") ");



Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: cm3rStakehldrCK of: com.picct.model.Cm3rStakehldr [select cm3rStakehldr.cm3rStakehldrCK.number from com.picct.model.Cm3rStakehldr cm3rStakehldr where cm3rStakehldr.wcmStkhrGrpNme in ('grp07084', 'grp01349', 'grp03239', 'grp04468', 'grp08619', 'grp08627', 'grp08630', 'grp01813', 'grp08646', 'grp01791', 'grp09005', 'grp09101', 'grp09210', 'grp09211', 'grp09212', 'grp09213', 'grp09222', 'grp09698', 'grp09675', 'grp01693', 'grp09180', 'grp09208', 'grp07085', 'grp09175', 'grp09174', 'grp09676', 'grp09176', 'grp09678', 'grp09677', 'grp09679', 'grp09681', 'grp09674', 'grp09178', 'grp09102', 'grp09100', 'grp09103', 'grp03223') ]; nested exception is org.hibernate.QueryException: could not resolve property: cm3rStakehldrCK of: com.picct.model.Cm3rStakehldr [select cm3rStakehldr.cm3rStakehldrCK.number from com.picct.model.Cm3rStakehldr cm3rStakehldr where cm3rStakehldr.wcmStkhrGrpNme in ('grp07084', 'grp01349', 'grp03239', 'grp04468', 'grp08619', 'grp08627', 'grp08630', 'grp01813', 'grp08646', 'grp01791', 'grp09005', 'grp09101', 'grp09210', 'grp09211', 'grp09212', 'grp09213', 'grp09222', 'grp09698', 'grp09675', 'grp01693', 'grp09180', 'grp09208', 'grp07085', 'grp09175', 'grp09174', 'grp09676', 'grp09176', 'grp09678', 'grp09677', 'grp09679', 'grp09681', 'grp09674', 'grp09178', 'grp09102', 'grp09100', 'grp09103', 'grp03223') ]
org.hibernate.QueryException: could not resolve property: cm3rStakehldrCK of: com.picct.model.Cm3rStakehldr [select cm3rStakehldr.cm3rStakehldrCK.number from com.picct.model.Cm3rStakehldr cm3rStakehldr where cm3rStakehldr.wcmStkhrGrpNme in ('grp07084', 'grp01349', 'grp03239', 'grp04468', 'grp08619', 'grp08627', 'grp08630', 'grp01813', 'grp08646', 'grp01791', 'grp09005', 'grp09101', 'grp09210', 'grp09211', 'grp09212', 'grp09213', 'grp09222', 'grp09698', 'grp09675', 'grp01693', 'grp09180', 'grp09208', 'grp07085', 'grp09175', 'grp09174', 'grp09676', 'grp09176', 'grp09678', 'grp09677', 'grp09679', 'grp09681', 'grp09674', 'grp09178', 'grp09102', 'grp09100', 'grp09103', 'grp03223') ]
   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.toType(BasicEntityPersister.java:1094)
   at org.hibernate.hql.ast.FromElementType.getPropertyType(FromElementType.java:273)
   at org.hibernate.hql.ast.FromElement.getPropertyType(FromElement.java:349)
   at org.hibernate.hql.ast.DotNode.getDataType(DotNode.java:474)
   at org.hibernate.hql.ast.DotNode.prepareLhs(DotNode.java:208)
   at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:166)
   at org.hibernate.hql.ast.DotNode.resolveFirstChild(DotNode.java:133)
   at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:324)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1812)
   at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1523)
   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:809)
   at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:358)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:800)
   at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:792)
   at com.picct.dao.Cm3rStakehldrDao.findChangeNumbersByContactOrGroup(Cm3rStakehldrDao.java:77)
   at com.picct.test.Cm3rStakehldrDaoTest.testFindChangeNumbersByContactOrGroup(Cm3rStakehldrDaoTest.java:63)
   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 junit.framework.TestSuite.runTest(TestSuite.java:208)
   at junit.framework.TestSuite.run(TestSuite.java:203)
   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)



Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 10:05 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
your query has cm3rStakehldr.cm3rStakehldrCK , but the name of the composite-id is Cm3rStakehldrCK . that should work, assuming you do have a getter and setter ;-)


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