简体   繁体   中英

Joda DateTime format to yyyy-MM-DD HH:MM:SS

This is the DateTime format that am getting using Joda DateTime 2019-01-10T13:59:36.700+05:30

 claimGroupingHistory.setCreatedAt(new DateTime());

But am getting the below error while inserting into the DB

2019-01-10 13:59:36,754 [http-9292-1] ERROR   org.hibernate.engine.jdbc.spi.SqlExceptionHelper: 146 - Data truncation: Incorrect datetime value: '\xAC\xED\x00\x05sr\x00\x16org.joda.time.DateTime\xB8<xdj[\xDD\xF9\x02\x00\x00xr\x00\x1Forg.joda.time.base.BaseDateTime\xFF\xFF\x' for column 'created_at' at row 1

How i can format Joda DateTime into yyyy-MM-DD HH:MM:SS this format to insert into the DB

Probably you should use for Hibernate 3:

@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")

on the field

And for Hibernate version 4-5 add the following:

@Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")

http://jadira.sourceforge.net/

https://mvnrepository.com/artifact/joda-time/joda-time-hibernate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM