使用hibernate框架时出现异常No CurrentSessionContext configured!

    使用hibernate框架时出现异常No CurrentSessionContext configured!

    因为可能你的HibernateUtil.java封装getSession()方法时使用的是sessionFactory.getCurrentSession();

    把它改成sessionFactory.openSession();

    或者在hibernate.cfg.xml配置文件上加上:

     <property name="hibernate.current_session_context_class">thread</property>

    就不会出现报错了

阅读更多

新手 No CurrentSessionContext configured!

07-24

在写一个使用hibernate的webservice,遇见rn[ERROR] No CurrentSessionContext configured!rnjava.lang.reflect.InvocationTargetExceptionrn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:497)rn at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:256)rn at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:121)rn at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)rn at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:106)rn at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:169)rn at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:242)rn at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:184)rn at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:869)rn at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:290)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at java.lang.Thread.run(Thread.java:745)rnCaused by: org.hibernate.HibernateException: No CurrentSessionContext configured!rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1012)rn at com.hzsiasun.dbbasic.dao.BaseDaoX.getSession(BaseDaoX.java:358)rn at com.hzsiasun.dbbasic.dao.BaseDaoEx.list(BaseDaoEx.java:222)rn at com.hzsiasun.service.HisManualMissionListService.queryList(HisManualMissionListService.java:15)rn at com.hzsiasun.release.MTRelase.HisList(MTRelase.java:19)rn ... 34 morernrn我加上thread 配置后就出现了,rn[INFO] HHH000397: Using ASTQueryTranslatorFactoryrnorg.hibernate.HibernateException: createQuery is not valid without active transactionrn at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)rn at com.sun.proxy.$Proxy6.createQuery(Unknown Source)rn at com.hzsiasun.dbbasic.dao.BaseDaoEx.list(BaseDaoEx.java:231)rn at com.hzsiasun.service.HisManualMissionListService.queryList(HisManualMissionListService.java:15)rn at com.hzsiasun.release.MTRelase.HisList(MTRelase.java:19)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:497)rn at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:256)rn at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:121)rn at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)rn at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:106)rn at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:169)rn at org.apache.axis2.transport.http.util.RESTUtil.invokeAxisEngine(RESTUtil.java:242)rn at org.apache.axis2.transport.http.util.RESTUtil.processURLRequest(RESTUtil.java:184)rn at org.apache.axis2.transport.http.AxisServlet$RestRequestProcessor.processURLRequest(AxisServlet.java:869)rn at org.apache.axis2.transport.http.AxisServlet.doGet(AxisServlet.java:290)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at java.lang.Thread.run(Thread.java:745)rnrn求解rn

org.hibernate.HibernateException: No CurrentSessionContext configured!

04-06

[b]Beans.xml 配置:[/b]rnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn classpath:jdbc.propertiesrn rn rnrn rn rn rn rn rn rn rn rn rn rn com.Alvin_yau.Spring.Modelrn rn rn rn rn rn org.hibernate.dialect.OracleDialectrn rn truern rn org.springframework.orm.hibernate4.SpringSessionContextrn rn rn rnrn rnrnrn rn rn rn rn rnrnrnrnrn————————————————————————————————————————————————rn————————————————————————————————————————————————rnrn@Component(value="userDao")rnpublic class UserDaoImpl implements UserDao rn rn private SessionFactory sessionFactory=null;rn rn public SessionFactory getSessionFactory() rn return sessionFactory;rn rn @Resourcern public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rnrn @Overridern public void add(Student student) rn // TODO Auto-generated method stubrn Session session=sessionFactory.getCurrentSession();rn session.save(student);rn rnrnrnrn@Component(value="logDao")rnpublic class LogDaoImpl implements LogDao rn private SessionFactory sessionFactory;rn rn public SessionFactory getSessionFactory() rn return sessionFactory;rn rn @Resourcern public void setSessionFactory(SessionFactory sessionFactory) rn this.sessionFactory = sessionFactory;rn rn rn @Overridern public void record(Log log) rn // TODO Auto-generated method stubrn Session session=sessionFactory.getCurrentSession();rn session.save(log);rn rnrnrn————————————————————————————————————————————————rn————————————————————————————————————————————————rnrn@Component(value="userService")rnpublic class UserService rn private UserDao userDao;rn private LogDao logDao;rnrn @Transactionalrn public void saveStu(Student student) rn userDao.add(student);rn Log log=new Log();rn log.setLog_name(student.getName()+" recorded.");rn log.setLog_date(new Date());rn logDao.record(log);rn rnrn public UserDao getUserDao() rn return userDao;rn rn rn @Resource(name="userDao")rn public void setUserDao(UserDao userDao) rn this.userDao = userDao;rn rnrn public LogDao getLogDao() rn return logDao;rn rn rn @Resource(name="logDao")rn public void setLogDao(LogDao logDao) rn this.logDao = logDao;rn rnrnrn————————————————————————————————————————————————rn————————————————————————————————————————————————rnrn @Testrn public void test() rn ClassPathXmlApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");rn System.out.println("****************************************************");rn UserService us=(UserService) ctx.getBean("userService");rn Student student=new Student();rn student.setName("tom");rn student.setPosition("student");rn us.saveStu(student);rn ctx.destroy();rn ctx.close();rn rnrnrnrnrnrn[b]报错:[/b]rnJunit:rnorg.hibernate.HibernateException: No CurrentSessionContext configured!rn at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1012)rnrnConsole:rnERROR: HHH000302: Unable to construct current session context [org.springframework.orm.hibernate4.SpringSessionContext]rnjava.lang.reflect.InvocationTargetExceptionrnrnCaused by: java.lang.NoClassDefFoundError: org/hibernate/service/jta/platform/spi/JtaPlatformrn at org.springframework.orm.hibernate4.SpringSessionContext.(SpringSessionContext.java:56)rn ... 61 morernCaused by: java.lang.ClassNotFoundException: org.hibernate.service.jta.platform.spi.JtaPlatform

JBPM+Spring 问题(No CurrentSessionContext configured)(求助)

04-26

spring配置文件(hibernate.cfg.xml中包含jbmp和项目中的hbm.xml配置文件)rnrn rn rnrnrn rn rnrnrn rnrnrn truern rn rn rn rn find*=PROPAGATION_REQUIRED,readOnly..... rn rnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnjbpm.cfg.xml 修改部分rnrn rn rn rn rn rn rn rn rn rnrnDAO配置rn rnrnQingjiaDAOImpl.javarnrnprivate void addNewProcess(Qingjia qj)rn // 走流程 rn JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); rn JbpmContext jbpmContext=jbpmConfiguration.getCurrentJbpmContext(); rn if(jbpmContext==null) rn jbpmContext=jbpmConfiguration.createJbpmContext(); rn rn log.info("jbpmContext=============="+jbpmContext);rn log.info("jbpmContext.getSession=============="+jbpmContext.getSession());rn rn ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("qingjia");rn rn ProcessInstance pi = pd.createProcessInstance();rn TaskInstance ti = pi.getTaskMgmtInstance().createStartTaskInstance();rn rn pi.getContextInstance().setVariable("userId",qj.getUser().getId());rn ti.setVariable("qingjiaId",qj.getId());rn ti.end();rnrnrnrn保存资料的时候总是报错,项目的资料都可以保存,但是流程就报错rnorg.hibernate.HibernateException: No CurrentSessionContext configured!rnat org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)rnat org.jbpm.persistence.db.DbPersistenceService.getSession(DbPersistenceService.java:105)rnat org.jbpm.JbpmContext.getSession(JbpmContext.java:506)rnat com.jbpmTest.dao.impl.QingjiaDAOImpl.addNewProcess(QingjiaDAOImpl.java:32)rn

没有更多推荐了,返回首页