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