Hello Guys
I am working with:
Spring Core 3.1.2.RELEASE, STS 3.0.0 + JDK 1.7
I have the follow Entity
the table isCode:@SuppressWarnings("serial") public class Cliente implements Serializable{ private String idCliente; private String nombreCliente; private String apellidoCliente; private Date fechaCliente; //setters/getters //toString }
Therefore same fields/variables in a 100%Code:create table cliente( idCliente varchar(10) not null, nombreCliente varchar(20) not null, apellidoCliente varchar(20) not null, fechaCliente timestamp not null, PRIMARY KEY(idCliente) )ENGINE=InnoDB;
My Dao Method
My Main classCode:@Transactional @Repository public class ClienteJdbcDaoImpl implements ClienteDaoService{ @Autowired private JdbcTemplate jdbcTemplate; @Override public void insertarCliente(Cliente cliente) { SqlParameterSource sqlParameterSource = new BeanPropertySqlParameterSource(cliente); jdbcTemplate.update("INSERT INTO cliente(idCliente, nombreCliente, apellidoCliente, fechaCliente) " + "VALUES(:idCliente, :nombreCliente, :apellidoCliente, :fechaCliente) ", sqlParameterSource ); } }
But when I execute the code I always getCode:ClienteBoService clienteBoService = (ClienteBoService) context.getBean(ClienteBoService.class); Cliente cliente = new Cliente(); cliente.setIdCliente("MJE"); cliente.setNombreCliente("Manuel"); cliente.setApellidoCliente("Jordan"); cliente.setFechaCliente(new Date()); clienteBoService.insertarCliente(cliente);
What is wrong?Code:Caused by: java.sql.SQLException: Invalid argument value: java.io.NotSerializableException at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) ... ... 28 more Caused by: java.io.NotSerializableException: org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346) at com.mysql.jdbc.PreparedStatement.setSerializableObject(PreparedStatement.java:4393) ... 38 more
I did the same than the code used in Spring Recipes 2nd Edition, the unique difference is that in the book it is working with the SimpleJdbcTemplate class where it is now deprecated and the API suggest use the jdbcTemplate.
I am doing this
Even more, even If use
I got the same resultsCode:Map<String, Object> parameters = new HashMap<String,Object>(); parameters.put("idCliente", cliente.getIdCliente()); parameters.put("nombreCliente",cliente.getNombreCliente()); parameters.put("apellidoCliente",cliente.getApellidoCliente()); parameters.put("fechaCliente",cliente.getFechaCliente()); SqlParameterSource sqlParameterSource = new MapSqlParameterSource(parameters);
What is wrong?
Thanks in advanced


Reply With Quote
...