invalid sql when using projection and restriction

Description

from this forum "discussion" (in fact it's a monologue): http://forum.hibernate.org/viewtopic.php?p=2398068#2398068

  • the criteria

Criteria criteria = getActorDao().createCriteria();
criteria.add(Restrictions.or(
Restrictions.ilike("name", "adi"),
Restrictions.ilike("description", "adi")
));
criteria.setProjection(Projections.projectionList()
.add(Projections.groupProperty("name"), "name")
.add(Projections.groupProperty("description"), "description")
);
criteria.setResultTransformer(new AliasToBeanResultTransformer(ActorTestDTO.class));
List result = criteria.list();

  • the generated SQL (show_sql=true):

select this_.name as y0_, this_.description as y1_
from Actor this_
left outer join Action this_1_ on this_.id=this_1_.id
left outer join Location this_2_ on this_.id=this_2_.id
left outer join UserGroup this_3_ on this_.id=this_3_.id
left outer join WebUser this_4_ on this_.id=this_4_.id
where (lower(y0_) like ? or lower(y1_) like ?)
group by this_.name, this_.description

  • the Problem
    This generated SQL works on HSQLDB but NOT on MS-SqlServer.
    The wrong code:
    where (lower(y0_) like ? or lower(y1_) like ?)


The correct code:
where (lower(this_.name) like ? or lower(this_.description) like ?)

I verified this by issuing the sql directly in SQL-server.

Activity

Show:

Steve EbersoleMarch 21, 2011 at 7:05 PM

Bulk closing stale resolved issues

Former userFebruary 27, 2009 at 7:31 PM

Another fix is proposed in HHH-817.

Former userFebruary 27, 2009 at 7:20 PM

A fix is proposed in HHH-3371.

Duplicate

Details

Assignee

Reporter

Components

Affects versions

Priority

Created October 27, 2008 at 1:08 PM
Updated March 21, 2011 at 7:05 PM
Resolved February 27, 2009 at 7:20 PM