我有一个latin1编码的mysql数据库,我想序列化到我的实体中。
我得到的是一个奇怪的错误,我认为这与db编码有关:
2016-04-18 23:52:32.765 DEBUG 41409 --- [pool-2-thread-1] org.hibernate.SQL : select newsletter0_.id_customer as id_custo1_0_, newsletter0_.active as active2_0_, newsletter0_.ape as ape3_0_, newsletter0_.birthday as birthday4_0_, newsletter0_.company as company5_0_, newsletter0_.date_add as date_add6_0_, newsletter0_.date_upd as date_upd7_0_, newsletter0_.deleted as deleted8_0_, newsletter0_.email as email9_0_, newsletter0_.firstname as firstna10_0_, newsletter0_.id_default_group as id_defa11_0_, newsletter0_.id_gender as id_gend12_0_, newsletter0_.id_lang as id_lang13_0_, newsletter0_.id_risk as id_risk14_0_, newsletter0_.id_shop as id_shop15_0_, newsletter0_.id_shop_group as id_shop16_0_, newsletter0_.ip_registration_newsletter as ip_regi17_0_, newsletter0_.is_guest as is_gues18_0_, newsletter0_.last_passwd_gen as last_pa19_0_, newsletter0_.lastname as lastnam20_0_, newsletter0_.max_payment_days as max_pay21_0_, newsletter0_.newsletter as newslet22_0_, newsletter0_.newsletter_date_add as newslet23_0_, newsletter0_.note as note24_0_, newsletter0_.optin as optin25_0_, newsletter0_.outstanding_allow_amount as outstan26_0_, newsletter0_.passwd as passwd27_0_, newsletter0_.secure_key as secure_28_0_, newsletter0_.show_public_prices as show_pu29_0_, newsletter0_.siret as siret30_0_, newsletter0_.website as website31_0_ from ps_customer newsletter0_
2016-04-18 23:52:32.769 WARN 41409 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S1009
2016-04-18 23:52:32.769 ERROR 41409 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Value '21�
0000-00-00�2016-04-10 18:01:472016-04-10 18:01:470test@gmail.comDanilo311011
172.19.0.202016-04-10 14:01:47Delizia012016-04-10 18:01:47�00.000000 de4a592876ec78ec014eb47a6cd1b49f 849de5fcc5bab384d4b5cc6089e010ed0��' can not be represented as java.sql.Timestamp
如果我在我的数据库上执行查询,我会在mysql workbench上得到结果。接口是hibernate无法正确解析结果。
我设置了以下属性:
spring.jpa.properties.hibernate.connection.characterEncoding=latin1
spring.jpa.properties.hibernate.connection.CharSet=latin1
但它仍然不起作用
答案 0 :(得分:2)
最后问题不是charset而是数据库中有价值的日期,如:" 0000-00-00"这不是java.sql.Timestamp或java.sql.Date所支持的,所以我不得不在连接字符串中添加以下参数zeroDateTimeBehavior=convertToNull
所以在属性中它将是:
spring.datasource.url=jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull