jax-rs Web服务无法使用休眠

时间:2015-07-24 03:03:10

标签: java mysql spring hibernate jax-rs

我得到的错误是什么能为它做什么?

输入例外报告

  

消息   org.springframework.transaction.CannotCreateTransactionException:   无法打开Hibernate Session进行事务处理;嵌套异常是   org.hibernate.exception.SQLGrammarException:无法打开连接

     

description服务器遇到阻止它的内部错误   完成此请求。

例外

  

org.jboss.resteasy.spi.UnhandledException:   org.springframework.transaction.CannotCreateTransactionException:   无法打开Hibernate Session进行事务处理;嵌套异常是   org.hibernate.exception.SQLGrammarException:无法打开连接     org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:76)     org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:212)     org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:149)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:372)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

  

org.springframework.transaction.CannotCreateTransactionException:   无法打开Hibernate Session进行事务处理;嵌套异常是   org.hibernate.exception.SQLGrammarException:无法打开连接     org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:515)     org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)     org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)     org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)     org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)     org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)     org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)     com.sun.proxy。$ Proxy34.getCustomer(Unknown Source)     com.resteasy.series.spring.hibernate.service.CustomerServiceImpl.getCustomerInfo(CustomerServiceImpl.java:33)     sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     java.lang.reflect.Method.invoke(Method.java:497)     org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)     org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

  

org.hibernate.exception.SQLGrammarException:无法打开连接     org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)     org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)     org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)     org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)     org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)     org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)     org.hibernate.internal.SessionImpl.connection(SessionImpl.java:427)     org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:429)     org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)     org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)     org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)     org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)     org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)     org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)     com.sun.proxy。$ Proxy34.getCustomer(Unknown Source)     com.resteasy.series.spring.hibernate.service.CustomerServiceImpl.getCustomerInfo(CustomerServiceImpl.java:33)     sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     java.lang.reflect.Method.invoke(Method.java:497)     org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)     org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

根本原因

  

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:Unknown   数据库' benchresources'     sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     java.lang.reflect.Constructor.newInstance(Constructor.java:422)     com.mysql.jdbc.Util.handleNewInstance(Util.java:408)     com.mysql.jdbc.Util.getInstance(Util.java:383)     com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4208)     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4140)     com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)     com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1747)     com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1287)     com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2494)     com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2527)     com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2309)     com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:834)     com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:46)     sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)     sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     java.lang.reflect.Constructor.newInstance(Constructor.java:422)     com.mysql.jdbc.Util.handleNewInstance(Util.java:408)     com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:419)     com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)     java.sql.DriverManager.getConnection(DriverManager.java:664)     java.sql.DriverManager.getConnection(DriverManager.java:208)     org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:173)     org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:164)     org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:153)     org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)     org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:141)     org.hibernate.internal.AbstractSessionImpl $ NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:301)     org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:214)     org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)     org.hibernate.internal.SessionImpl.connection(SessionImpl.java:427)     org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:429)     org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:372)     org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:417)     org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:255)     org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)     org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)     org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)     com.sun.proxy。$ Proxy34.getCustomer(Unknown Source)     com.resteasy.series.spring.hibernate.service.CustomerServiceImpl.getCustomerInfo(CustomerServiceImpl.java:33)     sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)     sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     java.lang.reflect.Method.invoke(Method.java:497)     org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137)     org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)     org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)     org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)     org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)     org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

注意Apache Tomcat / 8.0.23日志中提供了根本原因的完整堆栈跟踪。

1 个答案:

答案 0 :(得分:0)

在hibernate.cfg.xml中,检查以下属性

property name="hibernate.connection.url" jdbc:mysql://localhost:3306/benchresources property

如果存在则在MySql中创建一个数据库(如果你使用的是mysql),名称为“benchresources”