Restrictions not being applied when running EntityQuery from Action
padrino121 Sep 27, 2010 7:58 AM(project based off of seam-gen sources)
I have an action that parses an input file and builds Home objects to insert into a DB. After much trial and error I have that working fine however before insert I need to do a partial match on some of the columns to determine if the item already exists.
To check if the item exists I'm using the List EntityQuery class to build a query, the query executes fine and I can return a full list of everything in the database however the restrictions that work from the List.xhtml are not applied when executing from the action and I get a return of everything. I checked the List object and see that the object properties are set correctly, for reference this is the List EntityQuery:
@Name("productList") public class ProductList extends EntityQuery<Product> { /** * */ private static final long serialVersionUID = -7954123275209781511L; private static final String EJBQL = "select product from Product product"; private static final String[] RESTRICTIONS = { "lower(product.manufacturer) like lower(concat(#{productList.product.manufacturer},'%'))", "lower(product.partnumber) like lower(concat(#{productList.product.partnumber},'%'))", "lower(product.classcode) like lower(concat(#{productList.product.classcode},'%'))", "lower(product.subclass) like lower(concat(#{productList.product.subclass},'%'))",}; private Product product = new Product(); public ProductList() { setEjbql(EJBQL); setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS)); setMaxResults(25); } public Product getProduct() { return product; } }
In my action I do the following to configure the restrictions, right now it runs the query with no restrictions no matter the configuration, I've tried to build the restriction array directly in code and apply them but they also aren't used so I'm focusing on what looks like the proper way to do it. The Product object in ProductList has the properties set properly when the query is executed but there is no where clause added to the SQL, is there something I need to do in code to get the query to pickup the restrictions like it does when running from ProductList.xhtml
ProductList productList = new ProductList(); Product currentProduct = productList.getProduct(); currentProduct.setManufacturer(newProduct.getManufacturer()); currentProduct.setPartnumber(newProduct.getPartnumber()); currentProduct.setClasscode(newProduct.getClasscode()); currentProduct.setSubclass(newProduct.getSubclass());