Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate Springboot和mysql:读取latin1字符集_Hibernate_Jpa_Spring Boot - Fatal编程技术网

Hibernate Springboot和mysql:读取latin1字符集

Hibernate Springboot和mysql:读取latin1字符集,hibernate,jpa,spring-boot,Hibernate,Jpa,Spring Boot,我有一个mysql数据库,它是latin1编码的,我想序列化到我的实体中 我得到的是一个奇怪的错误,我认为这与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_, ne

我有一个mysql数据库,它是latin1编码的,我想序列化到我的实体中

我得到的是一个奇怪的错误,我认为这与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工作台上得到结果。很明显,hibernate无法正确解析结果

我设置了以下属性:

spring.jpa.properties.hibernate.connection.characterEncoding=latin1
spring.jpa.properties.hibernate.connection.CharSet=latin1

但它仍然不起作用

最后的问题不是字符集,而是数据库中有值的日期,如:“0000-00-00”,java.sql.Timestamp或java.sql.date不支持该日期,因此我必须在连接字符串中添加以下参数
zeroDateTimeBehavior=convertToNull

因此,在属性中,它将是:

spring.datasource.url=jdbc:mysql://localhost/test?zeroDateTimeBehavior=convertToNull