• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with named Query for a search

Divy Prakash
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All

I have a search query for which the sql statemanet i m using is

String lowerPriceLimit = null;
String higherPriceLimit = null;
lowerPriceLimit = searchForm.getPriceLowerRent();
higherPriceLimit = searchForm.getPriceHigherRent();
lowerPriceLimit = searchForm.getPriceLowerBuy();
higherPriceLimit = searchForm.getPriceHigherBuy();

final double lowerPrice = Double.parseDouble(lowerPriceLimit);
final double higherPrice = Double.parseDouble(higherPriceLimit);

StringBuffer query = new StringBuffer
("from " + getEntityBeanType().getName() + " p where ");

final int bedRoom = Integer.parseInt(searchForm.getNumberOfBedrooms());
query.append(" p.numberOfBedrooms >= '"+ bedRoom +"' and");

Long propertyCategory = (Long.valueOf(searchForm.getPropertyCategory()));
query.append(" p.propertyCategoryReferenceCode = '"+ propertyCategory +"' and");

Long residentialPropertyType = (Long.valueOf(searchForm.getResidentialPropertyType()));
query.append(" p.propertyTypeReferenceCode = '"+ residentialPropertyType +"' and");

Long commercialPropertyType = (Long.valueOf(searchForm.getCommercialPropertyType()));
query.append(" p.propertyTypeReferenceCode = '"+ commercialPropertyType +"' and");

Long city = (Long.valueOf(searchForm.getCity()));
query.append(" p.city = '"+ city +"' and");

query.append(" p.location= '"+searchForm.getLocation()+"' and");
query.append(" p.price between '" + lowerPrice +"' and '" + higherPrice +"'");

Now i need to write named queery for the search sql querry.

Well there can be some values which are null in the form so how 2 go for those values?

Do i need to create multiple named queriers?
Francois Nadeau
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Divy,

Yes, if I had to write named queries I would write multiple. Instead you may want to clean up your code by using a Criteria.

Hope this helps.
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!