Hello,
I am trying to test the findAll methods and getting a "Session closed" error. Interestingly, all my previous calls in the junit class succeed. Why would the session be closed and I do I resolve this?
Thanks
Service Manager Class:Code:javax.persistence.PersistenceException: org.hibernate.SessionException: Session is closed! at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:75) at diamelle.common.service.ServiceDAOBean.findAll(ServiceDAOBean.java:96) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:299) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196) at $Proxy21.findAll(Unknown Source) at diamelle.common.service.ServiceMgr.getAllServices(ServiceMgr.java:95) at diamelle.common.service.ServiceMgr$$FastClassByCGLIB$$28b3d4a2.invoke(<generated>) at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149) at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:621) at diamelle.common.service.ServiceMgr$$EnhancerByCGLIB$$81b521e2.getAllServices(<generated>) at test.diamelle.common.service.ServiceMgrTest.testGetAllServices(ServiceMgrTest.java:81) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at junit.framework.TestCase.runTest(TestCase.java:164) at junit.framework.TestCase.runBare(TestCase.java:130) at org.springframework.test.ConditionalTestCase.runBare(ConditionalTestCase.java:69) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:120) at junit.framework.TestSuite.runTest(TestSuite.java:228) at junit.framework.TestSuite.run(TestSuite.java:223) at org.junit.internal.runners.OldTestClassRunner.run(OldTestClassRunner.java:35) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.hibernate.SessionException: Session is closed! at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1110) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:66) ... 34 more
Service DAO classCode:public java.util.List<Service> getAllServices() { return serviceDao.findAll(); }
Service class:Code:@SuppressWarnings("unchecked") public List<Service> findAll() { log.debug("getting all Service instances " ); try { Query qry = entityManager.createNamedQuery("findAll"); return qry.getResultList(); // return entityManager.createNamedQuery("findAll").getResultList(); } catch (RuntimeException re) { log.error("get failed", re); throw re; } }
Code:@NamedQueries({ @NamedQuery( name = "findChildServices", query = "select s from Service s where s.parentServiceId = :id" ), @NamedQuery( name = "findAll", query = "select s from Service s " ), @NamedQuery( name = "findByType", query = "select s from Service s where s.serviceType = :type" ) })


Reply With Quote
="http://www.springframework.org/schema/p"