ActiveJdbc становится родителем в JSP

Недавно я начал использовать activejdbc для небольшого проекта Java EE, который я должен сделать для школы. Я пытаюсь получить значение поля внешнего ключа в таблице объектов БД, управляемой JDBC, в сервлете. Связи под рукой - это две таблицы, одна таблица "Исполнители" и одна таблица "Записи", последняя из которых содержит внешний ключ к PK исполнителя в таблице "Исполнители", так как Artist:Records = 1:n в моей модели.

Я хотел бы добиться следующего: у меня есть набор "записей" и я хочу получить соответствующего исполнителя для каждой записи в моем JSP. В моем Java-коде это работает нормально, выполнив только это:

    //Query the db:
    List<Record> mostRecentRecords = Record.findAll().limit(10).orderBy("id asc");

    for (Iterator i = mostRecentRecords.iterator(); i.hasNext(); ) {
        Record r = (Record) i.next();
        Artist a = r.parent(Artist.class);

        System.out.println("artist of record: " + a.get("artist_name"));
    }

В выводе моей консоли я вижу исполнителей, напечатанных на стандартный вывод.

Затем я перехожу к передаче этого списка в requestDispatcher и отрисовываю шаблон jsp.

По аналогии с этим я решил, что смогу сделать что-то подобное в моем jsp:

    <c:forEach items="${mostRecentRecords}" var="record">
        <c:out value="${record.parent(Artist.class).get('title')}" />
    </c:forEach>

Если я печатаю класс переменной "record" в цикле моего шаблона, он говорит "class model.Record", что правильно.

После рендеринга сервлета, однако, я получаю исключение org.apache.jasper.JasperException: javax.el.ELException: java.lang.NullPointerException.

Я включил полную трассировку стека ниже.

[2018-03-12T21:06:40.489+0100] [glassfish 5.0] [WARNING] [] [javax.enterprise.web.core] [tid: _ThreadID=29 _ThreadName=http-listener-1(2)] [timeMillis: 1520885200489] [levelValue: 900] [[
  Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.javalite.activejdbc.Model.parent(Model.java:1178)
    at org.javalite.activejdbc.Model.parent(Model.java:1167)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.el.ELUtil.invokeMethod(ELUtil.java:304)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:535)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:135)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:203)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1016)
    at org.apache.jsp.index_jsp._jspx_meth_c_out_3(index_jsp.java:235)
    at org.apache.jsp.index_jsp._jspx_meth_c_forEach_0(index_jsp.java:147)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:819)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:519)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:490)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:372)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:322)
    at servlet.Welcome.doGet(Welcome.java:38)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
    at java.lang.Thread.run(Thread.java:748)
]]

[2018-03-12T21:06:40.490+0100] [glassfish 5.0] [WARNING] [] [javax.enterprise.web] [tid: _ThreadID=29 _ThreadName=http-listener-1(2)] [timeMillis: 1520885200490] [levelValue: 900] [[
  StandardWrapperValve[welcome]: Servlet.service() for servlet welcome threw exception
java.lang.NullPointerException
    at org.javalite.activejdbc.Model.parent(Model.java:1178)
    at org.javalite.activejdbc.Model.parent(Model.java:1167)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at javax.el.ELUtil.invokeMethod(ELUtil.java:304)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:535)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:256)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:135)
    at com.sun.el.parser.AstValue.getValue(AstValue.java:203)
    at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226)
    at org.apache.jasper.runtime.PageContextImpl.evaluateExpression(PageContextImpl.java:1016)
    at org.apache.jsp.index_jsp._jspx_meth_c_out_3(index_jsp.java:235)
    at org.apache.jsp.index_jsp._jspx_meth_c_forEach_0(index_jsp.java:147)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:83)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
    at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:819)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:683)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:519)
    at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:490)
    at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:372)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:322)
    at servlet.Welcome.doGet(Welcome.java:38)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:686)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:463)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
    at java.lang.Thread.run(Thread.java:748)
]]

0 ответов

Другие вопросы по тегам