2011-12-21 80 views
1

我試圖在mysql中使用strpersist,但沒有成功。在eclipse上配置Hibernate,stripersist

我已經複製了條紋書,email23的示例代碼到eclipse並將res文件夾添加爲源文件夾。

當我嘗試運行應用程序我碰到下面的錯誤

SEVERE: Servlet.service() for servlet DispatcherServlet threw exception 
java.lang.NullPointerException 
    at stripesbook.dao.impl.stripersist.BaseDaoImpl.read(BaseDaoImpl.java:46) 
    at stripesbook.ext.MyActionBeanContext.getUser(MyActionBeanContext.java:60) 
    at stripesbook.action.BaseActionBean.getUser(BaseActionBean.java:93) 
    at stripesbook.action.ContactListActionBean.getContacts(ContactListActionBean.java:44) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:83) 
    at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) 
    at org.apache.el.parser.AstValue.getValue(AstValue.java:123) 
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) 
    at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:938) 
    at org.apache.jsp.WEB_002dINF.jsp.contact_005flist_jsp._jspService(contact_005flist_jsp.java:177) 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386) 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646) 
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436) 
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374) 
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302) 
    at net.sourceforge.stripes.action.ForwardResolution.execute(ForwardResolution.java:110) 
    at net.sourceforge.stripes.controller.DispatcherHelper$7.intercept(DispatcherHelper.java:483) 
    at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:158) 
    at net.sourceforge.stripes.controller.HttpCacheInterceptor.intercept(HttpCacheInterceptor.java:99) 
    at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) 
    at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113) 
    at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155) 
    at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74) 
    at net.sourceforge.stripes.controller.DispatcherHelper.executeResolution(DispatcherHelper.java:477) 
    at net.sourceforge.stripes.controller.DispatcherServlet.executeResolution(DispatcherServlet.java:293) 
    at net.sourceforge.stripes.controller.DispatcherServlet.doPost(DispatcherServlet.java:177) 
    at net.sourceforge.stripes.controller.DispatcherServlet.doGet(DispatcherServlet.java:67) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:246) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) 
    at java.lang.Thread.run(Thread.java:680) 

我已經檢查這個線程,Help configuring Hibernate,Jpa, Stripesist on Stripes,但仍然有任何幫助表示讚賞問題

+0

我會承擔Stripersist爲空在這種情況下,這意味着它沒有啓動正確。 Stripersist在啓動時是否有任何堆棧跟蹤?關於strpersist的任何日誌成功啓動? – lucas 2011-12-21 17:44:22

回答

0

您的代碼沒有對返回null的getEntityManager():

45: public T read(ID id) { 
46: return Stripersist.getEntityManager().find(entityClass, id); 
47: } 

這意味着你沒有休眠/ JPA爲Web應用程序配置正確。

您可能會發現這個文檔有用(雖然你可以按照任何的Hibernate/JPA配置指南,因爲配置不Stripersist或條紋專用): http://www.stripesframework.org/display/stripes/Hibernate+configuration