Olá pessoas,
Um projeto utilizando VRaptor + Hibernate caiu de para-quedas na minha mão e estou com uma dificuldade, acredito que simples, para capturar uma exception lançada.
Já dei uma estudada na FJ28, já busquei em vários tópicos aqui e nada do que esta aqui ajudou muito.
Enfim,
Tenho no meu controller, que estende de um controller genérico, um método save que chama o método save de seu pai. Este por sua vez chama o método add de uma implementação de repository genérico.
Controller: SistemaController extends GenericController
@Post("/sistema/save")
@Override
public void save(Sistema sistema) {
//em caso de qualquer exceção no repositório redireciona para o método save (GET)
getResult().on(Exception.class).forwardTo(this).saveError();
super.save(sistema);
addSucessMessage("Inclusão efetuada com sucesso");
getResult().redirectTo("/sistema/novo");
}
GenericController implements Controller
@Override
public void save(E object) {
validator.validate(object);
validator.onErrorUsePageOf(this).form();
repository.add(object);
}
RepositoryHibernateImpl implements Repository
@Override
public void add(E object) throws RepositoryExceptionHandler {
session.save(object);
}
Quando tento, propositalmente, inserir um sistema que já esta cadastrado na base, não consigo pegar a exceção em lugar nenhum. Nem com a forma especificada na documentação “getResult().on(‘Exceção lançada’)”
Pelo debug o código passa normalmente por essa linha e não faz nada e lança a mensagem de erro na tela:
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
br.com.caelum.vraptor.util.hibernate.HibernateTransactionInterceptor.intercept(HibernateTransactionInterceptor.java:50)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.unimedfortaleza.sabius.tecnologia.sso.interceptor.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:71)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.unimedfortaleza.sabius.tecnologia.sso.interceptor.NoCacheInterceptor.intercept(NoCacheInterceptor.java:64)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)
br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92)
br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)
br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89)
root cause
java.sql.BatchUpdateException: ORA-00001: unique constraint (SSO.SISTEMA_PK) violated
oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10698)
org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:184)
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
br.com.caelum.vraptor.util.hibernate.HibernateTransactionInterceptor.intercept(HibernateTransactionInterceptor.java:50)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.unimedfortaleza.sabius.tecnologia.sso.interceptor.AuthorizationInterceptor.intercept(AuthorizationInterceptor.java:71)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.unimedfortaleza.sabius.tecnologia.sso.interceptor.NoCacheInterceptor.intercept(NoCacheInterceptor.java:64)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:71)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)
br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)
br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:92)
br.com.caelum.vraptor.ioc.spring.SpringProvider.provideForRequest(SpringProvider.java:58)
br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:89)
Sou novo no VRaptor e ainda estou tentando entender o controle de exceções utilizando o Hibernate.
Só para adicionar informação, meu web.xml esta assim:
<context-param>
<param-name>br.com.caelum.vraptor.packages</param-name>
<param-value>
br.com.caelum.vraptor.util.hibernate,
br.com.caelum.vraptor.http,
br.com.caelum.vraptor.http.iogi,
br.com.caelum.vraptor.util.extjs
</param-value>
</context-param>
Qualquer ajuda será de grande valia!
Abraços.