In this post to the Hibernate forum, Gavin stated that there's no support for collections of value types in the Criteria API right now:
http://forum.hibernate.org/viewtopic.php?t=931999
As almost 2 years have passed by by now, this limitation still seems to be valid. Imagine the following mapping scenario:
Code:
<hibernate-mapping>
<class name="com.kesselheim.hibernatedemo.Project" table="PROJECTS">
<id name="id" column="IdProject" type="java.lang.Integer">
<generator class="native"/>
</id>
... other properties go here...
<set name="members" table="MEMBERS" lazy="false"
cascade="save-update">
<cache usage="read-write" />
<key column="IdProject" foreign-key="fk_member_project" />
<element type="com.kesselheim.hibernatedemo.LDAPPerson">
<column name="IdPerson" />
<column name="LDAPDistinguishedName" />
</element>
</set>
</class>
</hibernate-mapping>
The LDAPPerson type will then transparently "map in" all external data (e.g. name, address, etc.) as provided by the LDAP backend. Nevertheless, the entity relationship is not affected by this "seperation of concern" between hibernate and LDAP:
Code:
n n
Project<--------->Person
|
member
If I now want to query for all projects that person A takes part in, I can simple use a HQL query such as
Code:
from com.kesselheim.hibernatedemo.Project as project left join fetch project.members as member where member.id = ? and project.status = ?
Unfortunately, with both criterias and filters, it's not that easy. Calling Criteria.createAlias("members") results in a Hibernate exception beeing thrown, stating that the collection did not contain entity types. Same for property expressions and all the other stuff listed in the Hibernate docs.
Relying on HQL queries only becomes difficult on those occasions were really fancy query screens come into play, with lots of optional criterias and stuff. Hence, in order to prevent your application from committing string concatination suicide, it'ld be actually very helpful if one could rely on good old Criteria API.
What do you think? Did I miss something?
Best regards,
Chris