dcsimg
EJB3...What's not to Like?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Abhijit_Paralikar
Posted On:   Friday, April 11, 2008 09:46 AM

I recently was stuck at a place where I was required to construct a query with 'LIKE' clause in JPQL. I tried WHERE o.name LIKE ?1 but that just returned an exact match, I've tried WHERE o.name LIKE ?1% but that caused parser problems, I've tried WHERE o.name LIKE '?1%' and it did not return anything. Finally I got a not so elegant solution, but the one which worked. The relevant code is as below. Can someone explain why is it so? public class TestFoodController extends PageFlowController { private FoodControl myControl; public Collection results; private final static String WILDCARD = "%"; ... /** * @j   More>>

I recently was stuck at a place where I was required to construct a query with 'LIKE' clause in JPQL.



I tried WHERE o.name LIKE ?1 but that just returned an exact match, I've tried WHERE o.name LIKE ?1% but that caused parser problems, I've tried WHERE o.name LIKE '?1%' and it did not return anything.



Finally I got a not so elegant solution, but the one which worked. The relevant code is as below. Can someone explain why is it so?



			
public class TestFoodController extends PageFlowController
{

private FoodControl myControl;
public Collection results;
private final static String WILDCARD = "%";
...


/**
* @jpf:action
* @jpf:forward name="success" path="results.jsp"
*/
protected Forward findByName(FindByNameForm form)
{
try
{
results=myControl.findByName(form.getName() + WILDCARD );
} catch(Throwable t)
{
t.printStackTrace();
}

return new Forward("success");
}



Thanks,
Abhijit    <<Less
About | Sitemap | Contact