How to query with one restriction "is not null"
daxxy Jun 25, 2009 3:47 PMI am using the latest release of Seam, 2.1.2.
I would like to populate a select list with the results of this query
select distinct peRouter.peRouterName from PeRouter peRouter
where peRouterName is not null order by peRouterName
Here is how I thought I could implement it:
@Name("peRouterList") public class PeRouterList extends EntityQuery<PeRouter> { private static final String EJBQL = "select distinct peRouter.peRouterName " + "from PeRouter peRouter"; private static final String[] RESTRICTIONS = {"peRouter.peRouterName IS NOT NULL"}; private PeRouter peRouter = new PeRouter(); public PeRouterList() { setEjbql(EJBQL); setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS)); setOrderColumn("peRouter.peRouterName"); } public PeRouter getPeRouter() { return peRouter; } }
I get an exception and I can't figure out why:
Caused by: java.lang.IllegalArgumentException: there should be exactly one value binding in a restriction: org.jboss.seam.core.Expressions$1@ef07b8 at org.jboss.seam.framework.Query.parseEjbql(Query.java:230) at org.jboss.seam.framework.EntityQuery.createQuery(EntityQuery.java:175) at org.jboss.seam.framework.EntityQuery.initResultList(EntityQuery.java:79) at org.jboss.seam.framework.EntityQuery.getResultList(EntityQuery.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.jboss.seam.util.Reflections.invoke(Reflections.java:22) at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56) at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:97) at org.jboss.seam.util.Work.workInTransaction(Work.java:47) at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:91) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44) at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68) at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107) at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185) at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103) at dne.nmt.ond.action.PeRouterList_$$_javassist_seam_5.getResultList(PeRouterList_$$_javassist_seam_5.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at javax.el.BeanELResolver.getValue(BeanELResolver.java:62) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53) at org.jboss.el.parser.AstValue.getValue(AstValue.java:67) at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71) ... 80 more
How do I do this? I know I could just add a where clause to my EJBQL query, but I'd still like to know why this doesn't work. The setOrderColumn is working fine. I tested it by itself.
Thanks,
TDR