-->
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.  [ 1 post ] 
Author Message
 Post subject: Need help w/ Criteria query + polymorphic property
PostPosted: Tue Jul 11, 2006 2:36 pm 
Regular
Regular

Joined: Thu Apr 15, 2004 1:12 pm
Posts: 55
This application uses Hibernate 3.0, I think :-), and I wrote a query that looks like this:

Code:
      final DetachedCriteria crit = DetachedCriteria.forClass (Order.class);
      if (lastName != null) {
         crit.add (Restrictions.like ("nameLast", lastName));
      } else if (cardNumber != null) {
         crit.createCriteria ("purchaseTransaction.payment.delegate.verisignTransactionTraits.creditCard")
               .add (Restrictions.eq (
                     "searchKey",
                     CreditCard.searchKey (cardNumber)
                  ));
               }
               // etc...


...and I get this exception:

Code:
Caused by: org.hibernate.QueryException: could not resolve property: searchKey of: us.rocketsurgery.ecommerce.payment.AbstractPayment
        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.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:403)
...etc...


Now, my mapping is as shown below... note, the class AbstractPayment that the exception is complaining about is the class of the object denoted by "delegate" in the criteria association path. Anyway, here it is:

Code:
<hibernate-mapping>
  <class
      name="us.rocketsurgery.ecommerce.payment.AbstractPayment"
      table="payment"
      discriminator-value="0"
      lazy="false"
    >
    <id name="id">
      <generator class="increment"/>
    </id>
    <discriminator column="type" type="byte"/>

    <subclass        name="us.rocketsurgery.ecommerce.creditcards.OLTP.verisign.VerisignPayment"
        discriminator-value="1"
      >
      <component name="verisignTransactionTraits">
        <parent name="transaction"/>
        <!-- BasicCardTransactionTraits -->
        <component name="creditCard">
          <property name="number" column="cc_num"/>
          <property name="type">
            <column
                name="cc_type"
                sql-type="smallint"
              />
            <type name="us.rocketsurgery.hibernate.enumeration.EnumUserType">
              <param name="class">us.rocketsurgery.ecommerce.creditcards.CreditCardType</param>
            </type>
          </property>
          <property name="searchKey" column="cc_search_key"/>
         
          ...etc...


So... it's like the associationPath in the criterion gets faked out by the subclass. Does anyone know how I can code this correctly, or how to workaround, etc.?

Many thanks,
Mark


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

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.