JPA和服务器时区错误

时间:2016-08-22 08:46:24

标签: java mysql jpa jdbc

无论我在phpmyadmin或persistence.xml中的连接字符串中更改时区,我都会收到此错误:

 com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: 
 The server time zone value 'Romance Summer Time' is unrecognized or represents more than one time zone. 
 You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

这是我的persistence.xml:

<persistence-unit name="booking" transaction-type="RESOURCE_LOCAL">
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/_boekingdb_/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value=""/>
            <property name="hibernate.show_sql" value="true"/>
        </properties>
    </persistence-unit>

添加

?useUnicode=true&amp;useJD‌​BCCompliantTimezoneS‌​hift=true&amp;useLeg‌​acyDatetimeCode=fals‌​e&amp;serverTimezone‌​=UTC"

到jdbc.url connectionstring什么都不做

我甚至不知道这个“浪漫夏日时光”来自哪里。

任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

简单地添加

default-time-zone=+00:00

到my.ini(在xamp \ mysql \ bin中)修复了所有内容......

答案 1 :(得分:0)

serverTimezone=UTC添加到

<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/_boekingdb_/>

,效果很好。结果是

<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/_boekingdb_/?serverTimezone=UTC>