Hello.
I'm getting NullPointerException when adding %enum field% IS (NOT) NULL or == (!=) NULL in WHERE clause. The same exception using CriteriaQuery.
java.lang.NullPointerException at com.objectdb.o.REG.z(REG.java:310) at com.objectdb.o.REG.u(REG.java:161) at com.objectdb.o.CMN.<init>(CMN.java:130) at com.objectdb.o.CMN$aA.<init>(CMN.java:325) at com.objectdb.o.CMN$aB.<init>(CMN.java:417) at com.objectdb.o.CMN.av(CMN.java:73) at com.objectdb.o.QNF.q(QNF.java:530) at com.objectdb.o.QNF.k(QNF.java:195) at com.objectdb.o.QNF.j(QNF.java:135) at com.objectdb.o.QRC.B(QRC.java:340) at com.objectdb.o.QRC.x(QRC.java:231) at com.objectdb.o.QRC.w(QRC.java:185) at com.objectdb.o.QRM.Vb(QRM.java:272) at com.objectdb.o.MST.Vb(MST.java:949) at com.objectdb.o.WRA.Vb(WRA.java:311) at com.objectdb.o.WSM.Vb(WSM.java:115) at com.objectdb.o.QRR.g(QRR.java:244) at com.objectdb.o.QRR.f(QRR.java:153) at com.objectdb.jpa.JpaQuery.getResultList(JpaQuery.java:716) at com.sun.enterprise.container.common.impl.QueryWrapper.getResultList(QueryWrapper.java:84) at TestBean.postConstruct(TestBean.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.invokeMethods(DefaultLifecycleCallbackInvoker.java:89) at org.jboss.weld.injection.producer.DefaultLifecycleCallbackInvoker.postConstruct(DefaultLifecycleCallbackInvoker.java:73) at org.jboss.weld.injection.producer.BasicInjectionTarget.postConstruct(BasicInjectionTarget.java:95) at org.jboss.weld.injection.producer.BeanInjectionTarget.postConstruct(BeanInjectionTarget.java:65) at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:161) at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103) at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93) at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) at org.jboss.weld.proxies.TestBean$Proxy$_$$_WeldClientProxy.getEntities(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.el.BeanELResolver.getValue(BeanELResolver.java:363) at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) at com.sun.el.parser.AstValue.getValue(AstValue.java:140) at com.sun.el.parser.AstValue.getValue(AstValue.java:204) at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226) at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) at javax.faces.component.UIData.getValue(UIData.java:732) at javax.faces.component.UIData.getDataModel(UIData.java:1822) at javax.faces.component.UIData.setRowIndexWithoutRowStatePreserved(UIData.java:484) at javax.faces.component.UIData.setRowIndex(UIData.java:473) at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:83) at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:864) at javax.faces.component.UIData.encodeBegin(UIData.java:1133) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1854) at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:461) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) at java.lang.Thread.run(Thread.java:744) ]]
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core"> <f:view> <h:form> <h:commandButton value="Run a method" action="#{test.method}"/> </h:form> <h:dataTable value="#{test.entities}" var="e"> <h:column>#{e.id}</h:column> </h:dataTable> <h:messages /> </f:view> </html>
Entity:
@Entity @SequenceGenerator(name = "asd", allocationSize = 1) public class TEntity { public enum ExampleEnum { P1, P2 } @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "asd") private int id; @Enumerated(EnumType.STRING) private ExampleEnum exampleEnum; public int getId() { return id; } public void setId(int id) { this.id = id; } public ExampleEnum getExampleEnum() { return exampleEnum; } public void setExampleEnum(ExampleEnum exampleEnum) { this.exampleEnum = exampleEnum; } }
Manager:
@Stateless @TransactionManagement(TransactionManagementType.BEAN) public class TestManager { @Resource private UserTransaction transaction; @PersistenceContext(unitName = "my-pu") private EntityManager entityManager; public void persist(Object o) { try { transaction.begin(); entityManager.persist(o); transaction.commit(); } catch (NotSupportedException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } catch (RollbackException e) { e.printStackTrace(); } catch (HeuristicMixedException e) { e.printStackTrace(); } catch (HeuristicRollbackException e) { e.printStackTrace(); } } }
Bean:
@Named("test") @RequestScoped public class TestBean { @PersistenceContext(unitName = "my-pu") private EntityManager entityManager; @EJB private TestManager testManager; private List<TEntity> entities; @PostConstruct private void postConstruct() { Query query = entityManager.createQuery("SELECT e FROM TEntity e WHERE e.exampleEnum IS NULL"); entities = query.getResultList(); } public void method() { TEntity entity = new TEntity(); testManager.persist(entity); } public List<TEntity> getEntities() { return entities; } public void setEntities(List<TEntity> entities) { this.entities = entities; } }