我有一个具有此属性的对象
@Entity
public class Professor {
...
@Embedded
private List<Rating> ratings = new ArrayList<Rating>();
...
}
@Embeddable
public class Rating {
@Id
@GeneratedValue
private Long id;
private int rate;
private String comment;
...
}
但是当我尝试使用它时,即使使用新的 ArrayList... 实例,我也会得到一个空指针。
public int getAverageRating() {
if (!this.ratings.isEmpty()) {
return calculateRating();
}
return NO_RATINGS;
}
有谁知道在这里可以做什么?我是休眠、注释和 vraptor 的新手。
02:25:14,588 ERROR [io.undertow.request] (default task-4) UT005023: Exception handling request to /prorate/WEB-INF/jsp/professor/get.jsp: javax.servlet.ServletException: /WEB-INF/jsp/professor/get.jsp raised an exception
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:122) [vraptor-4.1.0.Final.jar:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129) [sitemesh-2.4.2.jar:]
at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77) [sitemesh-2.4.2.jar:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:113) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:240) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:227) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:73) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:146) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:177) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:727) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.8.0_20]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.8.0_20]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.8.0_20]
Caused by: org.apache.jasper.JasperException: javax.el.ELException: java.lang.NullPointerException
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410) [jastow-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326) [jastow-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259) [jastow-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at br.com.caelum.vraptor.core.DefaultStaticContentHandler.deferProcessingToContainer(DefaultStaticContentHandler.java:87) [vraptor-4.1.0.Final.jar:]
at br.com.caelum.vraptor.core.DefaultStaticContentHandler$Proxy$_$$_WeldClientProxy.deferProcessingToContainer(Unknown Source) [vraptor-4.1.0.Final.jar:]
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:109) [vraptor-4.1.0.Final.jar:]
at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:25) [undertow-core-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:229) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.handlers.ServletInitialHandler.dispatchToPath(ServletInitialHandler.java:172) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at io.undertow.servlet.spec.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:159) [undertow-servlet-1.0.15.Final.jar:1.0.15.Final]
at br.com.caelum.vraptor.view.DefaultPageResult.defaultView(DefaultPageResult.java:81) [vraptor-4.1.0.Final.jar:]
at br.com.caelum.vraptor.observer.ForwardToDefaultView.forward(ForwardToDefaultView.java:67) [vraptor-4.1.0.Final.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.8.0_20]
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:165) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:46) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:119) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:112) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.EventImpl.fire(EventImpl.java:83) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at br.com.caelum.vraptor.observer.RequestHandlerObserver.handle(RequestHandlerObserver.java:94) [vraptor-4.1.0.Final.jar:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.8.0_20]
at org.jboss.weld.injection.MethodInjectionPoint.invokeOnInstanceWithSpecialValue(MethodInjectionPoint.java:93) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:266) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:253) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:232) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:169) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObserver(ObserverNotifier.java:165) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.TransactionalObserverNotifier.notifyObserver(TransactionalObserverNotifier.java:46) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.notifyObservers(ObserverNotifier.java:119) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.ObserverNotifier.fireEvent(ObserverNotifier.java:112) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.jboss.weld.event.EventImpl.fire(EventImpl.java:83) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:118) [vraptor-4.1.0.Final.jar:]
... 32 more
Caused by: javax.el.ELException: java.lang.NullPointerException
at javax.el.BeanELResolver.getValue(BeanELResolver.java:368) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:109) [jastow-1.0.0.Final.jar:1.0.0.Final]
at com.sun.el.parser.AstValue.getValue(AstValue.java:140) [javax.el-3.0.0.jar:]
at com.sun.el.parser.AstValue.getValue(AstValue.java:204) [javax.el-3.0.0.jar:]
at com.sun.el.parser.AstEqual.getValue(AstEqual.java:58) [javax.el-3.0.0.jar:]
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:226) [javax.el-3.0.0.jar:]
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:898) [jastow-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jsp.WEB_002dINF.jsp.professor.get_jsp._jspx_meth_c_005fwhen_005f0(get_jsp.java:239)
at org.apache.jsp.WEB_002dINF.jsp.professor.get_jsp._jspx_meth_c_005fchoose_005f0(get_jsp.java:209)
at org.apache.jsp.WEB_002dINF.jsp.professor.get_jsp._jspx_meth_page_005fapply_002ddecorator_005f0(get_jsp.java:131)
at org.apache.jsp.WEB_002dINF.jsp.professor.get_jsp._jspService(get_jsp.java:83)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:69) [jastow-1.0.0.Final.jar:1.0.0.Final]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [jboss-servlet-api_3.1_spec-1.0.0.Final.jar:1.0.0.Final]
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:366) [jastow-1.0.0.Final.jar:1.0.0.Final]
... 83 more
Caused by: java.lang.NullPointerException
at com.xde.model.Professor.getAverageRating(Professor.java:53) [classes:]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_20]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [rt.jar:1.8.0_20]
at java.lang.reflect.Method.invoke(Unknown Source) [rt.jar:1.8.0_20]
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363) [jboss-el-api_3.0_spec-1.0.3.Final.jar:1.0.3.Final]