persistence@glassfish.java.net

_at_NamedQuery for finding details from more than 1 column

From: Eve Pokua <gorgeous65_at_msn.com>
Date: Fri, 04 May 2007 15:44:37 +0100

Hello everyone,

I am trying to write a query and method to help me get details from a
database
as below:

Itemcode Name Description Size Colour Price
4547887 table red table 15 inch red 1.30
5468679 table null null null null

I would like to write a query which would allow a search/find details in the
database
by either using Itemcode or name or description as below:

Find item by description/Code/name:

So far when I use the following query, I get the following error at
deployment:

@NamedQuery(name = "GetItemsbydescption",query = "SELECT i FROM
Iteamdetailsent i WHERE i.description= :description i.itmid=:itmid Or
i.itmname=:itmname"),


Exception Description: Syntax error parsing the query [SELECT i FROM
Iteamdetailsent i WHERE i.description= :description i.itmid=:itmid Or
i.itmname=:itmname], unexpected token [i].


And in my implementation, I am using the following method:

//retrieving items by description/ item code or item name
     public List<Iteamdetailhlp> Despcodename(String description, String
itmname, String itmid){
             List<Iteamdetailsent> iteamdetailsent=null;
             //Iteamdetailsent iteamdetailsents=null;
                 if (description!=null){
                try{

                        iteamdetailsent=(List<Iteamdetailsent>)
em.createNamedQuery("GetItemsbydescption").setParameter("description",
description).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");

                }//end of catch
                 }
             else if (itmname!=null){
             iteamdetailsent=(List<Iteamdetailsent>)
em.createNamedQuery("Getitemswithname").setParameter("itmname",
itmname).getResultList();
             }
             else if(itmid!=null){
             
iteamdetailsent=(List<Iteamdetailsent>)em.find(Iteamdetailsent.class,
itmid);}

                 return copyToDetails(iteamdetailsent);
        }//end of Despcodename


Somehow I don't thing I am on the right track.

I would appreciate any suggestion. Please, do not hesitate to ask for more
details. Thanks

eve

_________________________________________________________________
MSN Hotmail is evolving - check out the new Windows Live Hotmail
http://get.live.com/betas/mail_betas