Dear Community
I have the follow POJO
I have the follow table (MySQL 5.5.28)Code:package com.manuel.jordan.domain; import java.io.Serializable; import java.util.Date; import org.joda.time.DateTime; public class Persona implements Serializable{ private static final long serialVersionUID = 1L; private String idPersona; private String nombrePersona; private String apellidoPersona; private DateTime fechaPersona; setters/getters @Override public String toString() { .... }
And it is my repositoryCode:create table persona( idPersona varchar(10) not null, nombrePersona varchar(20) not null, apellidoPersona varchar(20) not null, fechaPersona timestamp not null, PRIMARY KEY(idPersona) )ENGINE=InnoDB;
In the Main class I create the Person class and call the serviceCode:@Transactional @Repository public class PersonaJdbcDaoImpl implements PersonaDaoService{ @Autowired private JdbcTemplate jdbcTemplate; @Override public void insertarPersona(Persona persona){ jdbcTemplate.update("INSERT INTO persona(idPersona, nombrePersona, apellidoPersona, fechaPersona) " + "VALUES(?,?,?,?) ", new Object[]{persona.getIdPersona(), persona.getNombrePersona(), persona.getApellidoPersona(), persona.getFechaPersona()} ); } }
But sadly I got this errorCode:Persona persona = new Persona(); persona.setIdPersona("MJE"); persona.setNombrePersona("Manuel"); persona.setApellidoPersona("Jordan"); persona.setFechaPersona(new DateTime("2012-12-25")); personaBoService.insertarPersona(persona);
I already did a research in Google through many hours, but all is related with Hibernate.Code:Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '??' for column 'fechaPersona' at row 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4072)
And event worst, seems the unique solution available in the web is this page
Joda DateTime to Java SQL Timestamp storing into MySQL via Hibernate ORM – Timezone Problems
Perhaps some member in the community has a solution.
I am assuming you are working with a repository standalone for JDBC (Spring's jdbcTemplate support) or MyBatis. Nothing related with some JPA annotation. And of course you are working with DateTime (JodaTime)
How you work around this problem?
BTW, MySQL expectes the follow pattern
Thanks in advancedCode:mysql> select * from persona; +-----------+---------------+-----------------+---------------------+ | idPersona | nombrePersona | apellidoPersona | fechaPersona | +-----------+---------------+-----------------+---------------------+ | MJE | Manuel | Jordan | 2012-10-27 21:34:50 | +-----------+---------------+-----------------+---------------------+ 1 row in set (0.00 sec) mysql>


Reply With Quote
...
