CMP模糊搜索

@ejb.finder signature="java.util.Collection find(java.lang.String a)"
    query="select object(a) from customer a where a.customerId like like '" + a + "%'"
    result-type-mapping="Local"

@jboss.finder-query name="find" 
    query="select object(a) from customer a where a.customerId like '" + a + "%'"

是错误的写法,EJBQL不支持这样写法。写成like ?1就可以了。之后在调用方法的时候人为加一个%

@ejb.bean primkey-field="customerId"
@ejb.pk class="java.lang.String"

@jboss.persistence datasource="java:MSSQLDS"
       datasource-mapping="MS SQLSERVER2000"
       table-name="customer"
       

@ejb.finder signature="java.util.Collection find(java.lang.String a)"
    query="select object(a) from customer a where a.customerId like ?1"
    result-type-mapping="Local"

@jboss.finder-query name="find" 
    query="select object(a) from customer a where a.customerId like ?1"             
 */

public Collection FindCustomer(String key) throws EJBException{
try{
key = key + "%";
ArrayList result = new ArrayList();
CustomerLocalHome home = CustomerUtil.getLocalHome();
Collection res = home.find(key);
Iterator it = res.iterator();
while(it.hasNext()){
CustomerLocal a = (CustomerLocal)it.next();
result.add(new CustomerData(a));
}
return result;
}catch(Exception ex){
throw new EJBException(ex);
}

}

你可能感兴趣的:(CMP模糊搜索)