Home » Category » Enterprise Technologies

Enterprise Technologies: EJB-QL using LIKE

300| Sun, 23 Sep 2007 08:16:00 GMT| vijayjadhava| Comments (1)

I want to perform search by keyword on all fields of a table. Say I have a customer table with following fields:

FieldName Data Type

CustomerID Integer

CustomerName String

City String

I cannot use LIKE operator as follows:

"SELECT OBJECT(c) FROM Customer AS c WHERE c.CustomerName LIKE ?1"

This throws error as LIKE operator expects String fields only. Is there any way I can use LIKE operator or any other way to search by keywords on all field of any data type using EJB QL.

Keywords & Tags: ejb-ql, enterprise

URL: http://java.itags.org/java-enterprise/17002/
 
«« Prev - Next »» 1 helpful answers below.

SELECT OBJECT(c) FROM Customer AS c WHERE c.CustomerName LIKE ?1

as CustomerName field is of String type, if your finder method accepts a String parameter, that QL will work.

How do you expect to search by keywords on all field of any data type? If your customerID, which is of Integer type, is 8080, by passing a keyword "80" you'd like that entry to be selected out? If a field of Date type is 2005-03-16, by passing a keyword "March" you'd like that entry to be selected out too?

By the way, you may have to provide a home method for searching by keyword, and implement that home method by calling an ejbSelectByKeyword() method and appending "%" character at the begining and the end of the keyword parameter received by the home method.

Regards

heavyz

heavyza | Mon, 09 Jul 2007 21:27:00 GMT |

Enterprise Technologies Hot Answers

Enterprise Technologies New questions

Enterprise Technologies Related Categories