Olá pessoal estou com o velho problema do lazy initialization exception…ja rodei a net e não consegui achar a solução adequada para a forma que está configurada o meu projeto.
Ele esta assim:
Quem me prove as sessions é o vraptor atraves dessa linha no web.xml
<context-param>
<param-name>br.com.caelum.vraptor.packages</param-name>
<param-value>br.com.caelum.vraptor.util.hibernate</param-value>
</context-param>
dai dando uma fucada no manual do vraptor e implementei o interceptor que é listado lá no final da pagina para o padrao open session in view
http://vraptor.caelum.com.br/documentation/interceptors/
mudei a classe Database para Session e espero que o vraptor a injete no construtor…
@RequestScoped
@Intercepts
public class SessionInterceptor implements Interceptor {
private final Session controller;
private final Result result;
private final HttpServletRequest request;
public SessionInterceptor(Session controller, Result result, HttpServletRequest request) {
this.controller = controller;
this.result = result;
this.request = request;
}
public void intercept(InterceptorStack stack, ResourceMethod method,
Object instance) throws InterceptionException {
result.include("contextPath", request.getContextPath());
try {
controller.beginTransaction();
stack.next(method, instance);
controller.getTransaction().commit();
} finally {
if (controller.getTransaction().isActive()) {
controller.getTransaction().rollback();
}
controller.close();
}
}
public boolean accepts(ResourceMethod method) {
return true;
}
}
tive que fazer algumas adptacoes, so que quando eu rodo a aplicacao:
Servlet.service() for servlet default threw exception
org.hibernate.TransactionException: Transaction not successfully started
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:131)
at projeto.intercepts.SessionInterceptor.intercept(SessionInterceptor.java:35)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:53)
at br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:44)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:53)
at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:81)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:53)
at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:67)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:53)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:53)
at br.com.caelum.vraptor.core.DefaultRequestExecution.execute(DefaultRequestExecution.java:70)
at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92)
at br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:56)
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
galera dá um help ai…ja faz 2 dias que estou tentando conseguir isso e nao ta saindo =/ …
obrigado