Rodrigo_Sasaki 25 de jun. de 2013
javarodrigo 25 de jun. de 2013
Obrigado Rodrigo.
Alguém mais teria outra ideia?
fredericomaia10 26 de jun. de 2013
Já tentou implementar alguma das 4 soluções acima? Como foi?
javarodrigo 2 de jul. de 2013
boa tarde.
Tentei usar o filter ficou assim:
web.xml
<filter>
<filter-name> HibernateSessionFilter</filter-name>
<filter-class> br.bd.HibernateSessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name> HibernateSessionFilter</filter-name>
<url-pattern> /faces/*</url-pattern>
</filter-mapping>
o Filtro
package br.bd ;
import java.io.IOException ;
import javax.servlet.Filter ;
import javax.servlet.FilterChain ;
import javax.servlet.FilterConfig ;
import javax.servlet.ServletException ;
import javax.servlet.ServletRequest ;
import javax.servlet.ServletResponse ;
public class HibernateSessionFilter implements Filter {
@Override
public void doFilter ( ServletRequest req , ServletResponse res , FilterChain fc ) throws IOException , ServletException {
HibernateUtil . openSession ();
try {
HibernateUtil . currentSession (). beginTransaction ();
fc . doFilter ( req , res );
HibernateUtil . currentSession (). getTransaction (). commit ();
} catch ( Exception e ) {
HibernateUtil . currentSession (). getTransaction (). rollback ();
throw new ServletException ( e );
} finally {
HibernateUtil . closeCurrentSession ();
}
}
@Override
public void init ( FilterConfig c ) {
}
@Override
public void destroy () {
}
}
está dando o seguinte erro:
com . sun . faces . mgbean . ManagedBeanCreationException : Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado subGrupoBean
at com . sun . faces . mgbean . BeanBuilder . invokePostConstruct ( BeanBuilder . java : 227 )
at com . sun . faces . mgbean . BeanBuilder . build ( BeanBuilder . java : 103 )
at com . sun . faces . mgbean . BeanManager . createAndPush ( BeanManager . java : 409 )
at com . sun . faces . mgbean . BeanManager . create ( BeanManager . java : 269 )
at com . sun . faces . el . ManagedBeanELResolver . resolveBean ( ManagedBeanELResolver . java : 244 )
at com . sun . faces . el . ManagedBeanELResolver . getValue ( ManagedBeanELResolver . java : 116 )
at com . sun . faces . el . DemuxCompositeELResolver .< em > getValue ( DemuxCompositeELResolver . java : 176 )
at com . sun . faces . el . DemuxCompositeELResolver . getValue ( DemuxCompositeELResolver . java : 203 )
at com . sun . el . parser . AstIdentifier . getValue ( AstIdentifier . java : 116 )
at com . sun . el . parser . AstValue . getBase ( AstValue . java : 151 )
at com . sun . el . parser . AstValue . getValue ( AstValue . java : 200 )
at com . sun . el . ValueExpressionImpl . getValue ( ValueExpressionImpl . java : 226 )
at org . jboss . weld . el . WeldValueExpression . getValue ( WeldValueExpression . java : 50 )
at com . sun . faces . facelets . el . ELText $ ELTextVariable . writeText ( ELText . java : 227 )
at com . sun . faces . facelets . compiler . TextInstruction . write ( TextInstruction . java : 85 )
at com . sun . faces . facelets . compiler . UIInstructions . encodeBegin ( UIInstructions . java : 82 )
at com . sun . faces . facelets . compiler . UILeaf . encodeAll ( UILeaf . java : 183 )
at org . primefaces . component . panelgrid . PanelGridRenderer . encodeFacet ( PanelGridRenderer . java : 169 )
at org . primefaces . component . panelgrid . PanelGridRenderer . encodeEnd ( PanelGridRenderer . java : 47 )
at javax . faces . component . UIComponentBase . encodeEnd ( UIComponentBase . java : 924 )
at javax . faces . component . UIComponent . encodeAll ( UIComponent . java : 1863 )
at javax . faces . render . Renderer . encodeChildren ( Renderer . java : 176 )
at javax . faces . component . UIComponentBase . encodeChildren ( UIComponentBase . java : 894 )
at javax . faces . component . UIComponent . encodeAll ( UIComponent . java : 1856 )
at javax . faces . component . UIComponent . encodeAll ( UIComponent . java : 1859 )
at javax . faces . component . UIComponent . encodeAll ( UIComponent . java : 1859 )
at com . sun . faces . application . view . FaceletViewHandlingStrategy . renderView ( FaceletViewHandlingStrategy . java : 443 )
at com . sun . faces . application . view . MultiViewHandler . renderView ( MultiViewHandler . java : 131 )
at javax . faces . application . ViewHandlerWrapper . renderView ( ViewHandlerWrapper . java : 337 )
at com . sun . faces . lifecycle . RenderResponsePhase . execute ( RenderResponsePhase . java : 120 )
at com . sun . faces . lifecycle . Phase . doPhase ( Phase . java : 101 )
at com . sun . faces . lifecycle . LifecycleImpl . render ( LifecycleImpl . java : 219 )
at javax . faces . webapp . FacesServlet . service ( FacesServlet . java : 647 )
at org . apache . catalina . core . StandardWrapper . service ( StandardWrapper . java : 1682 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 344 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 214 )
at org . primefaces . webapp . filter . FileUploadFilter . doFilter ( FileUploadFilter . java : 79 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 256 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 214 )
at br . bd . HibernateSessionFilter . doFilter ( HibernateSessionFilter . java : 19 )
at org . apache . catalina . core . ApplicationFilterChain . internalDoFilter ( ApplicationFilterChain . java : 256 )
at org . apache . catalina . core . ApplicationFilterChain . doFilter ( ApplicationFilterChain . java : 214 )
at org . apache . catalina . core . StandardWrapperValve . invoke ( StandardWrapperValve . java : 316 )
at org . apache . catalina . core . StandardContextValve . invoke ( StandardContextValve . java : 160 )
at org . apache . catalina . core . StandardPipeline . doInvoke ( StandardPipeline . java : 734 )
at org . apache . catalina . core . StandardPipeline . invoke ( StandardPipeline . java : 673 )
at com . sun . enterprise . web . WebPipeline . invoke ( WebPipeline . java : 99 )
at org . apache . catalina . core . StandardHostValve . invoke ( StandardHostValve . java : 174 )
at org . apache . catalina . connector . CoyoteAdapter . doService ( CoyoteAdapter . java : 357 )
at org . apache . catalina . connector . CoyoteAdapter . service ( CoyoteAdapter . java : 260 )
at com . sun . enterprise . v3 . services . impl . ContainerMapper . service ( ContainerMapper . java : 188 )
at org . glassfish . grizzly . http . server . HttpHandler . runService ( HttpHandler . java : 191 )
at org . glassfish . grizzly . http . server . HttpHandler . doHandle ( HttpHandler . java : 168 )
at org . glassfish . grizzly . http . server . HttpServerFilter . handleRead ( HttpServerFilter . java : 189 )
at org . glassfish . grizzly . filterchain . ExecutorResolver $ 9. execute ( ExecutorResolver . java : 119 )
at org . glassfish . grizzly . filterchain . DefaultFilterChain . executeFilter ( DefaultFilterChain . java : 288 )
at org . glassfish . grizzly . filterchain . DefaultFilterChain . executeChainPart ( DefaultFilterChain . java : 206 )
at org . glassfish . grizzly . filterchain . DefaultFilterChain . execute ( DefaultFilterChain . java : 136 )
at org . glassfish . grizzly . filterchain . DefaultFilterChain . process ( DefaultFilterChain . java : 114 )
at org . glassfish . grizzly . ProcessorExecutor . execute ( ProcessorExecutor . java : 77 )
at org . glassfish . grizzly . nio . transport . TCPNIOTransport . fireIOEvent ( TCPNIOTransport . java : 838 )
at org . glassfish . grizzly . strategies . AbstractIOStrategy . fireIOEvent ( AbstractIOStrategy . java : 113 )
at org . glassfish . grizzly . strategies . WorkerThreadIOStrategy . run0 ( WorkerThreadIOStrategy . java : 115 )
at org . glassfish . grizzly . strategies . WorkerThreadIOStrategy . access $ 100 ( WorkerThreadIOStrategy . java : 55 )
at org . glassfish . grizzly . strategies . WorkerThreadIOStrategy $ WorkerThreadRunnable . run ( WorkerThreadIOStrategy . java : 135 )
at org . glassfish . grizzly . threadpool . AbstractThreadPool $ Worker . doWork ( AbstractThreadPool . java : 564 )
at org . glassfish . grizzly . threadpool . AbstractThreadPool $ Worker . run ( AbstractThreadPool . java : 544 )
at java . lang . Thread . run ( Thread . java : 724 )
Caused by : com . sun . faces . spi . InjectionProviderException : com . sun . enterprise . container . common . spi . util . InjectionException : Exception attempting invoke lifecycle method public void br . controller . SubGrupoBean . initIt ()
at org . glassfish . faces . integration . GlassFishInjectionProvider . invokePostConstruct ( GlassFishInjectionProvider . java : 231 )
at com . sun . faces . mgbean . BeanBuilder . invokePostConstruct ( BeanBuilder . java : 221 )
… 67 more
Caused by : com . sun . enterprise . container . common . spi . util . InjectionException : Exception attempting invoke lifecycle method public void br . controller . SubGrupoBean . initIt ()
at org . glassfish . faces . integration . GlassFishInjectionProvider . invokeLifecycleMethod ( GlassFishInjectionProvider . java : 393 )
at org . glassfish . faces . integration . GlassFishInjectionProvider . invokePostConstruct ( GlassFishInjectionProvider . java : 306 )
at org . glassfish . faces . integration . GlassFishInjectionProvider . invokePostConstruct ( GlassFishInjectionProvider . java : 229 )
… 68 more
Caused by : java . security . PrivilegedActionException : java . lang . reflect . InvocationTargetException
at java . security . AccessController . doPrivileged ( Native Method )
at org . glassfish . faces . integration . GlassFishInjectionProvider . invokeLifecycleMethod ( GlassFishInjectionProvider . java : 376 )
… 70 more
Caused by : java . lang . reflect . InvocationTargetException
at sun . reflect . NativeMethodAccessorImpl . invoke0 ( Native Method )
at sun . reflect . NativeMethodAccessorImpl . invoke ( NativeMethodAccessorImpl . java : 57 )
at sun . reflect . DelegatingMethodAccessorImpl . invoke ( DelegatingMethodAccessorImpl . java : 43 )
at java . lang . reflect . Method . invoke ( Method . java : 606 )
at org . glassfish . faces . integration . GlassFishInjectionProvider $ 2. run ( GlassFishInjectionProvider . java : 382 )
… 72 more
Caused by : org . hibernate . LazyInitializationException : could not initialize proxy - no Session
at org . hibernate . proxy . AbstractLazyInitializer . initialize ( AbstractLazyInitializer . java : 164 )
at org . hibernate . proxy . AbstractLazyInitializer . getImplementation ( AbstractLazyInitializer . java : 285 )
at org . hibernate . proxy . pojo . javassist . JavassistLazyInitializer . invoke ( JavassistLazyInitializer . java : 185 )
at br . entidades . Secao </ em >$$< em > javassist_0 . getId ( Secao </ em >$$ _javassist_0 . java )
at br . controller . SubGrupoBean . atualizaGrupo ( SubGrupoBean . java : 135 )
at br . controller . SubGrupoBean . initIt ( SubGrupoBean . java : 58 )
… 77 more
Alguem pode me dar uma força?