2013-06-03 60 views
0

我使用Wicket的1.5.x版本彈簧3.2,並的Hibernate 3.6。我的應用程序成功地啓動並從數據庫讀取,但是當我嘗試實際加載頁面時,我得到了下面粘貼的異常。的NullPointerException在HibernateDaoSupport.getSession()

爲什麼找不到會話?從我可以告訴它甚至沒有可怕的LazyLoadInitializationException,所以我甚至不知道從哪裏開始,我不確定它在頁面渲染過程中得到了足夠多的信息,以判斷OpenSessionInViewFilter是否會有所幫助。

@ContextConfiguration(locations = { "classpath:testApplicationContext.xml" }) 
@TransactionConfiguration(transactionManager = "txManager") 
@RunWith(SpringJUnit4ClassRunner.class) 
public abstract class AbstractWebPageTests implements ApplicationContextAware 

我使用註釋線了我的測試類:

org.apache.wicket.WicketRuntimeException: Exception in rendering component: [TooltipContainer [Component id = firstNameTip]] 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2590) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.form.Form.onComponentTagBody(Form.java:1656) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.Page.onRender(Page.java:907) 
    at org.apache.wicket.markup.html.WebPage.onRender(WebPage.java:140) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.Page.renderPage(Page.java:1035) 
    at org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:118) 
    at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:246) 
    at org.apache.wicket.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:167) 
    at org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:784) 
    at org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64) 
    at org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:255) 
    at org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:212) 
    at org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:283) 
    at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:696) 
    at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:624) 
    at org.apache.wicket.util.tester.BaseWicketTester.processRequest(BaseWicketTester.java:596) 
    at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1257) 
    at org.apache.wicket.util.tester.BaseWicketTester.startPage(BaseWicketTester.java:1230) 
    at us.ak.state.revenue.cssd.Personnel.Pages.MaintenanceForms.Employee.TestChangeRequestMaintenance.__CLR3_1_11lo23k3ciu(TestChangeRequestMaintenance.java:52) 
    at us.ak.state.revenue.cssd.Personnel.Pages.MaintenanceForms.Employee.TestChangeRequestMaintenance.testLoadPageLoggedIn_DO(TestChangeRequestMaintenance.java:49) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) 
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) 
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41) 
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) 
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) 
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220) 
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) 
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137) 
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:77) 
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) 
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) 
Caused by: java.lang.RuntimeException: An error occurred while getting the model object for Component: [TextField [Component id = firstName, page = us.ak.state.revenue.cssd.Personnel.Pages.MaintenanceForms.Employee.ChangeRequestMaint, path = 0:emp_info_maint:firstNameTip:firstName.TextField, isVisible = true, isVersioned = false, markup = [markup = file:/C:/Users/tfburton/Documents/JavaProjects/SVN/Personnel/trunk/target/classes/us/ak/state/revenue/cssd/Personnel/Pages/MaintenanceForms/Employee/ChangeRequestMaint.html 
<input wicket:id="firstName" type="text" class="noChange"/>, index = 0, current = '<input wicket:id="firstName" type="text" class="noChange"/>' (line 0, column 0)]]] 
    at org.apache.wicket.Component.getDefaultModelObject(Component.java:1679) 
    at org.apache.wicket.Component.getDefaultModelObjectAsString(Component.java:1701) 
    at org.apache.wicket.markup.html.form.FormComponent.getModelValue(FormComponent.java:1211) 
    at org.apache.wicket.markup.html.form.FormComponent.getValue(FormComponent.java:837) 
    at org.apache.wicket.markup.html.form.TextField.onComponentTag(TextField.java:108) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2534) 
    at org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1530) 
    at org.apache.wicket.Component.internalRender(Component.java:2393) 
    at org.apache.wicket.Component.render(Component.java:2321) 
    at org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1428) 
    at org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1592) 
    at org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1567) 
    at org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1521) 
    at org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:72) 
    at org.apache.wicket.Component.internalRenderComponent(Component.java:2563) 
    ... 104 more 
Caused by: org.apache.wicket.WicketRuntimeException: Error calling method: public java.lang.String us.ak.state.revenue.cssd.Personnel.dao.Employee.Employee.getFirstName() on object: null 
    at org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.getValue(PropertyResolver.java:1127) 
    at org.apache.wicket.util.lang.PropertyResolver$ObjectAndGetSetter.getValue(PropertyResolver.java:648) 
    at org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:102) 
    at org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:134) 
    at org.apache.wicket.Component.getDefaultModelObject(Component.java:1674) 
    ... 118 more 
Caused by: java.lang.NullPointerException 
    at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:143) 
    at us.ak.state.revenue.cssd.Personnel.dao.NameTableHome.findByPcn(NameTableHome.java:555) 
    at WICKET_us.ak.state.revenue.cssd.Personnel.dao.NameTableHome$$FastClassByCGLIB$$bd58bb2e.invoke(<generated>) 
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) 
    at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:333) 
    at WICKET_us.ak.state.revenue.cssd.Personnel.dao.NameTableHome$$EnhancerByCGLIB$$e12a569d.findByPcn(<generated>) 
    at us.ak.state.revenue.cssd.Personnel.dao.PcnTable.getNameTable(PcnTable.java:198) 
    at us.ak.state.revenue.cssd.Personnel.dao.Employee.Employee.getNameTable(Employee.java:697) 
    at us.ak.state.revenue.cssd.Personnel.dao.Employee.Employee.getFirstName(Employee.java:67) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.getValue(PropertyResolver 

UPDATE

我的測試類繼承以下的類。但我試圖堅持儘可能地使用XML來連接我的實際Web應用程序,該應用程序在我的測試開始時通過new WicketTester(new MockLoggedInApplication(user));加載。 MockLoggedInApplication extends QuickstartApplication並且我的應用程序在QuickStartApplication.init()內部執行了很多數據庫讀取操作。

我應該粘貼我的applicationContext.xml嗎?

注:

我想我已經縮小的問題。

如果你在底部Caused By:

Caused by: java.lang.NullPointerException 
    at org.springframework.orm.hibernate3.support.HibernateDaoSupport.getSession(HibernateDaoSupport.java:143) 
    at us.ak.state.revenue.cssd.Personnel.dao.NameTableHome.findByPcn(NameTableHome.java:555) 
    at WICKET_us.ak.state.revenue.cssd.Personnel.dao.NameTableHome$$FastClassByCGLIB$$bd58bb2e.invoke(<generated>) 
    at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:191) 
    at org.apache.wicket.proxy.LazyInitProxyFactory$CGLibInterceptor.intercept(LazyInitProxyFactory.java:333) 
    at WICKET_us.ak.state.revenue.cssd.Personnel.dao.NameTableHome$$EnhancerByCGLIB$$e12a569d.findByPcn(<generated>) 
    at us.ak.state.revenue.cssd.Personnel.dao.PcnTable.getNameTable(PcnTable.java:198) 
    at us.ak.state.revenue.cssd.Personnel.dao.Employee.Employee.getNameTable(Employee.java:697) 
    at us.ak.state.revenue.cssd.Personnel.dao.Employee.Employee.getFirstName(Employee.java:67) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at org.apache.wicket.util.lang.PropertyResolver$MethodGetAndSet.getValue(PropertyResolver 

仔細一看吾道我的檢票代理WICKET_us.ak.state.revenue.cssd.Personnel.dao.NameTableHome$$FastClassByCGLIB$$bd58bb2e.invoke(<generated>)處理。然而,儘管wicket對我來說代理它永遠不會被Spring事務管理抓住。

我的交易管理配置:

<bean id="sessionFactory" 
     class="us.ak.state.revenue.cssd.Personnel.utils.SessionFactoryBean" > 
    <property name="configLocation" value="classpath:hibernate.cfg.xml"> 
    </property> 
</bean> 

<bean id="txManager" 
    class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
    <property name="sessionFactory"> 
    <ref bean="sessionFactory" /> 
    </property> 
</bean> 

<tx:advice id="txAdvice" transaction-manager="txManager"> 
    <tx:attributes> 
     <tx:method name="find*"  propagation="REQUIRED"/> 
     <!-- others omitted for brevity --> 
    </tx:attributes> 
</tx:advice> 

<aop:config proxy-target-class="true" > 
    <aop:advisor advice-ref="txAdvice" 
      pointcut="execution(* *..BaseHibernateDAO+.find*(..))" /> 
    <!-- omitted for brevity --> 
</aop:config> 

<bean id="NameTableHome" 
     class="us.ak.state.revenue.cssd.Personnel.dao.NameTableHome" > 
    <property name="sessionFactory" ref="sessionFactory"/> 
</bean> 
<!-- other dao beans omitted for brevity --> 

NameTableHome聲明與此類似:

public class NameTableHome extends BaseHibernateDAO 
+1

如今,不推薦使用'HibernateDaoSupport'。 http://stackoverflow.com/a/5104965/870248 –

+0

此代碼最初使用** Spring-2.5.x **我已升級到** 3.2 **感謝我將考慮轉換我的基類一旦我得到我的應用程序再次工作。 – Raystorm

+0

它看起來像NPE發生在會議時。我會查看配置以查看SessionFactory是否未被創建或設置。但我認爲它會失敗,除非你使用Annotations來將東西連接在一起,並且無論出於何種原因,將SessionFactory連接到HibernateDAOSupport的東西將它設置爲required = false。 – CodeChimp

回答

0
在HibernateDaoSupport的基於代碼

:143(至少在我的版本,彈簧ORM 3.2。 2)我懷疑HibernateDaoSupport的字段hibernateTemplate爲null。你確定模板設置正確嗎?

相關問題