OK, I've got Criteria stuff (mostly) working for query-by-example and the code is simpler than building HQL, so that's good. However, I can't figure out how to build the correct criteria to do something like this:
Code:
TariffState tariffState = new TariffState();
TariffDelegate tariffDelegate = new TariffDelegate();
TariffPlaceState tariffPlace = new TariffPlaceState();
tariffPlace.setBillParentCode("DOD%");
Set tariffPlaces = new HashSet(1);
tariffPlaces.add(tariffPlace);
tariffState.setTariffPlaceStates(tariffPlaces);
System.out.println("Retrieving Tariffs w/ DOD% as bill parent");
PersistentStateList tariffs = tariffDelegate.find(tariffState);
for (PersistentStateIterator itr = tariffs.iterator(); itr.hasNext();) {
tariffState = (TariffState) itr.next();
System.out.println(tariffState);
}
Here's the relevant parts of my mappings:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.*****.cc.objectlib.tariff.TariffState"
schema="eousr"
table="TARIFF">
<meta attribute="extends">com.*****.cc.objectlib.PersistentState</meta>
<id name="id" type="java.lang.Long">
<column name="TARIFF_ID"/>
<generator class="assigned"/>
</id>
<version
name="lockCol"
type="long"
column="LOCK_COL"/>
<property
name="name"
type="java.lang.String"
column="NAME"
length="30">
<meta attribute="use-in-tostring">true</meta>
</property>
<!-- other properties deleted -->
<!-- associations -->
<!-- bi-directional one-to-many association to TariffPlaceState -->
<set
name="tariffPlaceStates"
lazy="true"
inverse="true">
<key>
<column name="TARIFF_ID"/>
</key>
<one-to-many
class="com.*****.cc.objectlib.tariff.TariffPlaceState"/>
</set>
<!-- other associations deleted -->
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<class
name="com.*****.cc.objectlib.tariff.TariffPlaceState"
schema="eousr"
table="TARIFF_PLACE">
<meta attribute="extends">com.*****.cc.objectlib.PersistentState</meta>
<composite-id name="id" class="com.*****.cc.objectlib.tariff.TariffPlaceIdentity">
<key-property name="seqId" column="SEQ_ID" type="java.lang.Long"/>
<key-property name="tariffId" column="TARIFF_ID" type="java.lang.Long"/>
<!-- <meta attribute="extends">com.*****.cc.objectlib.CompoundIdentity</meta> -->
</composite-id>
<version
name="lockCol"
type="long"
column="LOCK_COL"/>
<property
name="billParentCode"
type="java.lang.String"
column="BILL_PARENT_CD"
length="8">
<meta attribute="use-in-tostring">true</meta>
</property>
<!-- other properties deleted -->
<!-- associations -->
<!-- bi-directional many-to-one association to TariffState -->
<many-to-one
name="tariffState"
class="com.fedex.cc.objectlib.tariff.TariffState"
not-null="true"
update="false"
insert="false">
<column name="TARIFF_ID"/>
</many-to-one>
</class>
</hibernate-mapping>
Currently, my criteria looks like this (System.out.println(criteria);)
[tariffPlaceStates.billParentCode like DOD%]
But that throws an Exception:
Code:
Exception in thread "main" net.sf.hibernate.QueryException: unresolved property: tariffPlaceStates.billParentCode [null]
Start server side stack trace:
net.sf.hibernate.QueryException: unresolved property: tariffPlaceStates.billParentCode [null]
at net.sf.hibernate.persister.EntityPersister.toColumns(EntityPersister.java:965)
at net.sf.hibernate.expression.Expression.getColumns(Expression.java:282)
at net.sf.hibernate.expression.SimpleExpression.toSqlString(SimpleExpression.java:24)
at net.sf.hibernate.loader.CriteriaLoader.<init>(CriteriaLoader.java:43)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3149)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:65)
at com.*****.cc.objectlib.dao.HibernateDAO.find(HibernateDAO.java:269)
Thanks for any help.