Olá Gujeiros, comecei a estudar Java Web e V-Raptor a pouco tempo, estou acompanhando a apostila FJ-28 da Caelum mas fazendo um exemplo próprio com base na apostila. Criei um formulário de cadastro e quando clico no botão “Enviar” ocorre o seguinte erro:
22:14:45,156 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ParametersInstantiatorInterceptor
22:14:45,171 DEBUG [JstlLocalization ] couldn't find message bundle, creating an empty one
22:14:45,171 DEBUG [AsmBasedTypeCreator ] Trying to make class for ClienteController$adiciona$1171405073$1
22:14:45,203 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ClienteController.adiciona(Cliente) as [cliente]
22:14:45,203 DEBUG [AsmBasedTypeCreator ] Parameter names found for creating type are: [Cliente]
22:14:45,203 DEBUG [AsmBasedTypeCreator ] Method for field 'Cliente' being defined for type Lbr/bmweb/pojo/Cliente;
22:14:45,203 DEBUG [AsmBasedTypeCreator ] Methods: [public void ClienteController$adiciona$1171405073$1.setCliente(br.bmweb.pojo.Cliente), public br.bmweb.pojo.Cliente ClienteController$adiciona$1171405073$1.getCliente()]
22:14:45,203 DEBUG [AsmBasedTypeCreator ] Fields: [private br.bmweb.pojo.Cliente ClienteController$adiciona$1171405073$1.Cliente_]
22:14:45,203 DEBUG [CacheBasedTypeCreator] cached generic type for method [DefaultResourceMethod: ClienteController.adicionaClienteController.adiciona(Cliente)]
22:14:45,234 DEBUG [OgnlParametersProvider] Applying cliente.placa with [Placa]
22:14:45,281 DEBUG [OgnlParametersProvider] Applying cliente.mercado with [Mercado]
22:14:45,281 DEBUG [OgnlParametersProvider] Applying cliente.rg with [123]
22:14:45,281 DEBUG [OgnlParametersProvider] Applying cliente.data_nascimento with [10-07-1987]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.contato with [Ciclano]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.newsletter with [S]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.email with [cristiano@123]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.documento with [123]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.profissao with [Teste]
22:14:45,296 DEBUG [OgnlParametersProvider] Applying cliente.nome with [Cristiano]
22:14:45,312 DEBUG [OgnlParametersProvider] Applying cliente.data_cadastro with [10-01-2000]
22:14:45,312 DEBUG [ParanamerNameProvider] Found parameter names with paranamer for ClienteController.adiciona(Cliente) as [cliente]
22:14:45,312 DEBUG [ParametersInstantiatorInterceptor] Parameter values for [DefaultResourceMethod: ClienteController.adicionaClienteController.adiciona(Cliente)] are [br.bmweb.pojo.Cliente@1fa269b]
22:14:45,343 DEBUG [ToInstantiateInterceptorHandler] Invoking interceptor ExecuteMethodInterceptor
22:14:45,343 DEBUG [ExecuteMethodInterceptor] Invoking ClienteController.adiciona(Cliente)
Hibernate:
select
max(CL_COD_CLIENTE)
from
TB_CLIENTE
Hibernate:
insert
into
TB_CLIENTE
(CL_DOCUMENTO, CL_RG, CL_NOME, CL_CONTATO, CL_MERCADO, CL_PLACA, CL_EMAIL, CL_PROFISSAO, CL_DATA_NASCIMENTO, CL_DATA_CADASTRO, CL_NEWS_LETTER, CL_COD_CLIENTE)
values
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
12/03/2010 22:14:45 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet default threw exception
br.com.caelum.vraptor.InterceptionException: an exception was raised while executing resource method
at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:86)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
at br.com.caelum.vraptor.interceptor.ParametersInstantiatorInterceptor.intercept(ParametersInstantiatorInterceptor.java:77)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:42)
at br.com.caelum.vraptor.core.InstantiatedInterceptorHandler.execute(InstantiatedInterceptorHandler.java:47)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
at br.com.caelum.vraptor.interceptor.InterceptorListPriorToExecutionExtractor.intercept(InterceptorListPriorToExecutionExtractor.java:46)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:80)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
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:65)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:65)
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:128)
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:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:94)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1028)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:366)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at br.bmweb.dao.ClienteDao.salva(ClienteDao.java:23)
at br.bmweb.controller.ClienteController.adiciona(ClienteController.java:24)
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 br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:57)
... 37 more
Caused by: java.sql.BatchUpdateException: Column 'CL_DATA_NASCIMENTO' cannot be null
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
... 51 more
Minha classe ClienteDao está assim:
[code]package br.bmweb.dao;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Transaction;
import br.bmweb.pojo.;
import br.bmweb.util.;
import br.com.caelum.vraptor.ioc.Component;
@Component
public class ClienteDao {
private final Session session;
public ClienteDao(){
this.session=AbreSession.getSession();
}
public ClienteDao salva(Cliente cliente) {
Transaction tx = session.beginTransaction();
session.save(cliente);
tx.commit();
session.close();
return null;
}
public ClienteDao removeCliente(Cliente cliente){
Cliente cliente2 = (Cliente) session.load(Cliente.class, 1L);
Transaction tx = session.beginTransaction();
session.delete(cliente2);
tx.commit();
session.close();
return null;
}
public List<Cliente>listaTudo(){
return this.session.createCriteria(Cliente.class).list();
}
}
[/code]
Minha classe ClienteController está assim:
[code]package br.bmweb.controller;
import java.util.List;
import br.bmweb.dao.ClienteDao;
import br.bmweb.pojo.Cliente;
import br.com.caelum.vraptor.Resource;
@Resource
public class ClienteController {
private final ClienteDao dao;
public ClienteController(ClienteDao dao){
this.dao=dao;
}
public List<Cliente>lista(){
return dao.listaTudo();
}
public void formulario(){
}
public void adiciona(Cliente cliente){
ClienteDao dao = new ClienteDao();
dao.salva(cliente);
}
}[/code]
Meu formulario.jsp está assim:
[code]<%@ page language=“java” contentType=“text/html; charset=ISO-8859-1”
pageEncoding=“ISO-8859-1”%>
<%@ taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core”%>
Cadastro de Clientes Adicionar Cliente Documento:RG:
Nome:
Contato:
Mercado:
Placa:
E-mail:
Profissão:
Data Nascimento:
Data Cadastro:
NewsLetter:
Enviar [/code]
Pelo que notei o método “adiciona” da classe ClienteController está sendo setado com valor nulo. Devo modificar o método “adiciona” para que capture os dados do formulário? Como contornar este problema utilizando V-Raptor?