0

I have a simple JavaServer Faces (JSF) application that lists some cars. The app is deployed and I can get to the index locally. When I click on a page to see the list of all cars, my request to the server to list the cars does not work. I get this error:

StandardWrapperValve[Faces Servlet]: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NullPointerException: Cannot invoke "javax.persistence.EntityManagerFactory.createEntityManager()" because "this.emf" is null
    at controller.VehicleOfInterestJpaController.getEntityManager(VehicleOfInterestJpaController.java:38)
    at controller.VehicleOfInterestJpaController.findVehicleOfInterestEntities(VehicleOfInterestJpaController.java:215)
    at controller.VehicleOfInterestJpaController.findVehicleOfInterestEntities(VehicleOfInterestJpaController.java:211)
    at model.VehicleOfInterestController$1.createPageDataModel(VehicleOfInterestController.java:67)
    at model.VehicleOfInterestController.getItems(VehicleOfInterestController.java:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at jakarta.el.BeanELResolver.getValue(BeanELResolver.java:299)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:139)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:164)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:114)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:177)
    at com.sun.el.parser.AstEqual.getValue(AstEqual.java:34)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:183)
    at org.jboss.weld.module.web.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:73)
    at jakarta.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:188)
    at jakarta.faces.component.UIComponentBase.isRendered(UIComponentBase.java:310)
    at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1446)
    at jakarta.faces.render.Renderer.encodeChildren(Renderer.java:141)
    at jakarta.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:558)
    at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1453)
    at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1456)
    at jakarta.faces.component.UIComponent.encodeAll(UIComponent.java:1456)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:458)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:164)
    at jakarta.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:125)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:93)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:72)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:178)
    at jakarta.faces.webapp.FacesServlet.executeLifecyle(FacesServlet.java:682)
    at jakarta.faces.webapp.FacesServlet.service(FacesServlet.java:437)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1540)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:119)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:611)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:550)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:75)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:114)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:332)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:199)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:440)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:144)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:174)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:153)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:196)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:88)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:246)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:178)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:118)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:96)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:51)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:510)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:82)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:83)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:34)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:101)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515)
    at java.base/java.lang.Thread.run(Thread.java:833)

The Source Packages look like this:

├── controller
│   └── VehicleOfInterestJpaController.java
├── model
│   ├── VehicleOfInterest.java
│   └── VehicleOfInterestController.java

This is my faces-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
version="2.0">
    <application>
        <resource-bundle>
            <base-name>/Bundle</base-name>
            <var>bundle</var>
        </resource-bundle>
        <resource-bundle>
            <base-name>/Bundle</base-name>
            <var>bundle</var>
        </resource-bundle>
    </application>
    <managed-bean>
        <managed-bean-name>vehicleModelController</managed-bean-name>
        <managed-bean-class>model.VehicleModelController</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
</faces-config>
  • I use NetBeans 15, JSF 2.3. All the code was automatically generated by Netbeans and they're long so I don't think it'll be helpful to paste them here.
  • The database is running and I can query the data using NetBeans Services.
  • I've looked online and even used ChatGPT but couldn't find a working solution.
  • I'm only familiar with maven and using JSF is non-negotiable.
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Viet
  • 6,513
  • 12
  • 42
  • 74
  • The problem is in your code. According to the stacktrace `controller.VehicleOfInterestJpaController.getEntityManager` is attempting to use a `null` reference. That's about all we can tell you without seeing the relevant code. – Stephen C Jan 24 '23 at 02:41
  • In the absence of your code, I suggest that you read https://stackoverflow.com/questions/218384 and its answers. – Stephen C Jan 24 '23 at 02:43
  • 1
    Notwithstanding that ... it is unlikely that anyone will be able to figure what is causing the issue without seeing the relevant (generated) code. – Stephen C Jan 24 '23 at 03:24
  • FYI: described code is generated by Netbeans, not by JSF. So the issue is in Netbeans area not in JSF area. – BalusC Jan 24 '23 at 14:15

0 Answers0