antonio.gcn 28 de jun. de 2016
Cara da erro ao utilizar entityManager.unwrap
GRAVE : Servlet . service () for servlet [ dispatcher ] in context with path [ /ceos ] threw exception [ Request processing failed; nested exception is javax.persistence.PersistenceException: Hibernate cannot unwrap interface java.sql.Connection ] with root cause
javax . persistence . PersistenceException : Hibernate cannot unwrap interface java . sql . Connection
at org . hibernate . jpa . spi . AbstractEntityManagerImpl . unwrap ( AbstractEntityManagerImpl . java : 1524 )
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 . orm . jpa . SharedEntityManagerCreator $ SharedEntityManagerInvocationHandler . invoke ( SharedEntityManagerCreator . java : 289 )
at com . sun . proxy . $ Proxy45 . unwrap ( Unknown Source )
at br . gov . sp . saude . fmk . facade . EditorSQLFacade . executarComando ( EditorSQLFacade . java : 36 )
at br . gov . sp . saude . fmk . controller . EditorSQLController . executa ( EditorSQLController . java : 55 )
at br . gov . sp . saude . fmk . controller . EditorSQLController $$ FastClassBySpringCGLIB $$ e45ee74e . invoke ( < generated > )
at org . springframework . cglib . proxy . MethodProxy . invoke ( MethodProxy . java : 204 )
at org . springframework . aop . framework . CglibAopProxy $ CglibMethodInvocation . invokeJoinpoint ( CglibAopProxy . java : 717 )
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 157 )
at org . springframework . transaction . interceptor . TransactionInterceptor $ 1. proceedWithInvocation ( TransactionInterceptor . java : 98 )
at org . springframework . transaction . interceptor . TransactionAspectSupport . invokeWithinTransaction ( TransactionAspectSupport . java : 266 )
at org . springframework . transaction . interceptor . TransactionInterceptor . invoke ( TransactionInterceptor . java : 95 )
at org . springframework . aop . framework . ReflectiveMethodInvocation . proceed ( ReflectiveMethodInvocation . java : 179 )
at org . springframework . aop . framework . CglibAopProxy $ DynamicAdvisedInterceptor . intercept ( CglibAopProxy . java : 653 )
at br . gov . sp . saude . fmk . controller . EditorSQLController $$ EnhancerBySpringCGLIB $$ 8737386 e . executa ( < generated > )
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 . web . method . support . InvocableHandlerMethod . invoke ( InvocableHandlerMethod . java : 215 )
at org . springframework . web . method . support . InvocableHandlerMethod . invokeForRequest ( InvocableHandlerMethod . java : 132 )
at org . springframework . web . servlet . mvc . method . annotation . ServletInvocableHandlerMethod . invokeAndHandle ( ServletInvocableHandlerMethod . java : 104 )
at org . springframework . web . servlet . mvc . method . annotation . RequestMappingHandlerAdapter . invokeHandleMethod ( RequestMappingHandlerAdapter . java : 781 )
at org . springframework . web . servlet . mvc . method . annotation . RequestMappingHandlerAdapter . handleInternal ( RequestMappingHandlerAdapter . java : 721 )
at org . springframework . web . servlet . mvc . method . AbstractHandlerMethodAdapter . handle ( AbstractHandlerMethodAdapter . java : 83 )
at org . springframework . web . servlet . DispatcherServlet . doDispatch ( DispatcherServlet . java : 943 )
at org . springframework . web . servlet . DispatcherServlet . doService ( DispatcherServlet . java : 877 )
at org . springframework . web . servlet . FrameworkServlet . processRequest ( FrameworkServlet . java : 966 )
at org . springframework . web . servlet . FrameworkServlet . doPost ( FrameworkServlet . java : 868 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 644 )
at org . springframework . web . servlet . FrameworkServlet . service ( FrameworkServlet . java : 842 )
at javax . servlet . http . HttpServlet . service ( HttpServlet . java : 725 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 291 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . tomcat . websocket . server . WsFilter . doFilter ( WsFilter . java : 52 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 239 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 206 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 219 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 106 )
at org . apache . catalina . authenticator . AuthenticatorBase . invoke ( AuthenticatorBase . java : 505 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 142 )
at org . apache . catalina . valves . ErrorReportValve . invoke ( ErrorReportValve . java : 79 )
at org . apache . catalina . valves . AbstractAccessLogValve . invoke ( AbstractAccessLogValve . java : 610 )
at org . apache . catalina . core . StandardEngineValve . invoke ( StandardEngineValve . java : 88 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 534 )
at org . apache . coyote . http11 . AbstractHttp11Processor . process ( AbstractHttp11Processor . java : 1081 )
at org . apache . coyote . AbstractProtocol $ AbstractConnectionHandler . process ( AbstractProtocol . java : 658 )
at org . apache . coyote . http11 . Http11NioProtocol $ Http11ConnectionHandler . process ( Http11NioProtocol . java : 222 )
at org . apache . tomcat . util . net . NioEndpoint $ SocketProcessor . doRun ( NioEndpoint . java : 1566 )
at org . apache . tomcat . util . net . NioEndpoint $ SocketProcessor . run ( NioEndpoint . java : 1523 )
at java . util . concurrent . ThreadPoolExecutor . runWorker ( Unknown Source )
at java . util . concurrent . ThreadPoolExecutor $ Worker . run ( Unknown Source )
at org . apache . tomcat . util . threads . TaskThread $ WrappingRunnable . run ( TaskThread . java : 61 )
at java . lang . Thread . run ( Unknown Source )
antonio.gcn 28 de jun. de 2016 1 like
[RESOLVIDO] - Cara, muito obrigado , funcionou perfeitamente.
No DaoFactoryModel eu criei um metodo abaixo, utilizando o que você me passou, assim sempre que eu precisar estará lá:
public Connection getHibernateSession () {
Session hibernateSession = ( Session ) this .getEntityManager () .unwrap ( Session .class ) ;
Connection jdbcConnection = (( SessionImpl ) hibernateSession ) .connection () ;
return jdbcConnection ;
}