I know with 2.x I can perform have an arbitrary join in hql - but not using the Criteria API. With 3.x is it possible to perform arbitrary joins using the Criteria API, or are there plans to add this support?
The main reason I ask is all of our "search" forms use the criteria api to find objects. Criterias are easier to create using Example and add in associations as needed when compared to generating similar HQL.
However, I have run into a requirement that requires an arbitrary join and I'm hoping to continue to use the Criteria API.
I've gotten a sample query to work in HQL (using mysql). I can build the rest of the search lookup functionality if that's the only way. Just thought I would ask first since I didn't find anything in the docs about the Criteria API supporting this type of query.
As way of example here is the HQL. I'm trying to create something similar using the Criteria API.
Code:
Query q = s.createQuery(
"from com.entity.Person as person " +
" join person.organization as org, " +
" com.entity.Organization hier " +
"where hier.name like 'schawk%' " +
" and org.hierarchy like concat(hier.hierarchy, '%')"
);
The basic mapping is:
Code:
<class name="com.entity.Party" table="party" lazy="true" discriminator-value="X0">
<id name="partyID" type="long" unsaved-value="0" >
<generator class="identity"/>
</id>
<subclass name="com.entity.Person" discriminator-value="P" lazy="true">
<many-to-one name="organization" class="com.entity.Organization"
column="organization" cascade="save-update"/>
</subclass>
<subclass name="com.entity.Organization" discriminator-value="O" lazy="true">
<many-to-one name="parent" class="com.entity.Organization" cascade="save-update"
column="organization"/>
<property name="hierarchy" type="string" length="210" />
</subclass>
</class>
The hierarchy property is a concatenation of the parent's ids.
Thanks in advance,
Chris....