Sorry, no change.
addSort() is just a utility method that calls addOrder() if "sortParams" is not null.
Perhaps I've found the reason why it fails: I've mapped ContactDetails as a component...but the documentation says it can be treated as an ordinary association!!
Quote from Hibernate Reference, chapter 8.2:
"Composite elements may appear in queries using the same syntax as associations to other entities."
Uhm, I think that more details are needed. Here are the mapping files:
PersonData.hbm.xml
Code:
<hibernate-mapping package="studiodix.model">
<class name="PersonData" table="`PERSON_DATA`">
<id name="id" column="`PERSON_ID`" type="long">
<generator class="native" />
</id>
<component name="contactDetails" class="ContactDetails">
<property name="title" column="`TITLE`" type="string" length="16" />
<property name="firstName" column="`FIRST_NAME`" type="string" length="100" />
<property name="lastName" column="`LAST_NAME`" type="string" length="100" />
<property name="email" column="`EMAIL`" type="string" length="100" />
<property name="phone1" column="`PHONE1`" type="string" length="64" />
<property name="phone2" column="`PHONE2`" type="string" length="64" />
</component>
</class>
</hibernate-mapping>
Moreover, if I add "contactDetails." to the restrictions:
Code:
SimpleExpression lastNameLike =
Restrictions.like("contactDetails.lastName", name, MatchMode.START).ignoreCase();
SimpleExpression firstNameLike =
Restrictions.like("contactDetails.firstName", name, MatchMode.START).ignoreCase();
I get this absurd error:
Code:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: contactDetails of: studiodix.model.User; nested exception is org.hibernate.QueryException: could not resolve property: contactDetails of: studiodix.model.User
Caused by: org.hibernate.QueryException: could not resolve property: contactDetails of: studiodix.model.User
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.AbstractEntityPersister.toType(AbstractEntityPersister.java:1310)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:204)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:191)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:81)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:59)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$35.doInHibernate(HibernateTemplate.java:974)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:362)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:964)
at studiodix.dao.PersonDao.findByName(PersonDao.java:40)
I don't want to fallback to HQL, because I've already put in place a lot of utility code to leverage Detached query mechanism...