views:

101

answers:

3

Hi,

I have a sql statement which I want to move it into hibernate criteria, but I am not clue how to do this.

The problem is one of the WHERE clause which looks like the following

...(skip other parts)... ? ILIKE strprefix||'%' ...(continue)

strprefix is the column name, the ? is the place i need to fill in the value.

With criteria, I can use

criteria.add(Expression.ilike(propertyName, value));

but in this case, how can i do this.

Thanks in advance!

A: 

You can't do this in Criteria, columns are set since they represent the properties in your domain object. You need to query against the property not the other way around.

non sequitor
The closest you can get is `.add(Restrictions.eqProperty("propertyName","otherPropertyName")` which will not do what you want
non sequitor
A: 

but since sql statement can do that, i wonder if there is something equivalent in hibernate.

for example, I have a value 'abcde 126783', and in table, there store strprefix as abcde, so it will bring back that entry in database.

A: 

You can likely handle this with Restrictions.sqlRestriction(String sql).

Don Roby