My entity class:
@Entity
@Table(catalog = "emp", name = "person")
@XmlAccessorType(XmlAccessType.FIELD)
public class Person implements Serializable {
private static final long serialVersionUID = 1L;
/**
*/
@Column(name = "ID", nullable = false,length = 50)
@Basic(fetch = FetchType.EAGER)
@Id
@XmlElement
String id;
/**
*/
@Column(name = "ADDRESS", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String address;
/**
*/
@Column(name = "EMAIL", length = 50)
@Basic(fetch = FetchType.EAGER)
@XmlElement
String email;
@Column(name = "DATE")
@Basic(fetch = FetchType.EAGER)
@XmlElement
DateTime date;
/**
*/
/*getters and setters */
}
I'm using joda time for my date. When I persist, it throws this exception:
> Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'DATE' at row 1
My Date field contain this value : 2015-09-02T16:24:05.226+04:00
Below is the code where it persist in db:
public Person save(Person person) {
Person currentPerson = entityManager.find(Person.class,
person.getId());
if (currentPerson != null) {
entityManager.detach(currentPerson);
person =entityManager.merge(person);
} else {
entityManager.persist(person);
}
return person;
}
I am using hibernate/jpa and mysql. My database is created base on my entity class. my date is of type datetime in my entity class, but in database it is of type tinyblob.
How to solve this?