persistence@glassfish.java.net

Re: _at_NamedQuery for finding details from more than 1 column

From: Wouter van Reeven <wouter_at_van.reeven.nl>
Date: Tue, 8 May 2007 15:05:51 +0200

On Tue, May 08, 2007 at 12:23:34PM +0100, Eve Pokua wrote:
> I have tested your suggestions as below:
>
> Query from entity class:
>
> @NamedQuery(name = "GetItemsbydescption2",query = "SELECT i FROM
> Iteamdetailsent i WHERE i.description LIKE
> CONCAT('%',CONCAT(:description,'%') OR i.itmid LIKE
> CONCAT('%',CONCAT(:itmid,'%') OR i.itmname LIKE
> CONCAT('%',CONCAT(:itmname,'%')))"),
>
>
> and method for client to access in implementation stateful class:
>
> public List<Iteamdetailhlp> Despcodename2(String description){
> List<Iteamdetailsent> iteamdetailsent=null;
> //Iteamdetailsent iteamdetailsents=null;
> if (description!=null){
> try{
>
> iteamdetailsent=(List<Iteamdetailsent>)
> em.createNamedQuery("GetItemsbydescption2").getResultList();
> //iteamdetailsent=(List<Iteamdetailsent>)
> em.createNamedQuery("Getitemswithname").setParameter("itmname",
> itmname).getResultList();
> }catch(Exception ex){
> System.err.println("Can not get items details by
> Description entered. Name entered not recogniced");}}
>
>
> return copyToDetails(iteamdetailsent);
> }//end of Despcodename2
>
>
> I get the following error:
>
> Syntax error parsing the query [SELECT i FROM Iteamdetailsent i WHERE
> i.description LIKE CONCAT('%',CONCAT(:description,'%') OR i.itmid LIKE
> CONCAT('%',CONCAT(:itmid,'%') OR i.itmname LIKE
> CONCAT('%',CONCAT(:itmname,'%')))], unexpected token [LIKE].
>
>
>
> So far, i have found that the LIKE operator is not implemented in EJB2.

Ehrm EJB2?

> But since I am using EJB3, maybe there might be an answer somewhere. I will
> keep on looking to see if this can be resolved.

According to the EJB3 specification, then LIKE operator is implemented. See
pages 92 and 93 of the spec.


Wouter

-- 
People: "If she weighs the same as a Duck, she's made of wood!"
Sir Bedevere: "And therefore...?"