Catalina 更新后无法从 jpa 访问 mysql

Unable to access mysql from jpa after Catalina update

我的 jpa 应用程序运行良好(实际上,我的 2 个 jpa 应用程序),因为我将 mac 更新到 Catalina(当然,然后重新启动它)。

从那以后我得到了

org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator initiateService
WARN: HHH000342: Could not obtain connection to query metadata : null
Exception in thread "main" org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
...
Caused by: org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

但是从 mySQL Workbench 我可以毫无问题地访问我的数据库。

我尝试重新安装 mysql,甚至使用 brew 来完成。什么都不管用。 我的 persistence.xml 文件和代码都没有更改。

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="MyProject" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myschema"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.password" value="MyPassword"/>
      <property name="javax.persistence.schema-generation.database.action" value="update"/>
    </properties>
  </persistence-unit>
</persistence>

我的mysql版本是8.0.19.

谢谢!

次日更新(28/4):

到目前为止,我有: 1) 将这一行添加到我的 persistence.xml:

<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />

当我收到一个新错误...

Access denied for user 'root'@'localhost' (using password: YES)

2) 按照以下说明设置 root 密码: https://medium.com/@aungzanbaw/how-to-reset-root-user-password-in-mysql-8-0-a5c328d098a8

现在我的新错误是

Connection refused

次日更新(29/4):

今天我从终端mysql停止并启动:

sudo /usr/local/bin/mysql.server stop
sudo /usr/local/bin/mysql.server start

然后我得到一个新的错误

The server time zone value 'CEST' 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.

让我们继续调查!

关注这个问题:https://es.whosebug.com/questions/48935/configurar-zona-horaria-jdbc-driver-java/48946?newreg=494e1840d4404575a81dc4ec10200266

我修改了persistence.xml:

所以我得到了

Table 'myschema.mytable' doesn't exist

错误。

我终于明白了,但不确定如何...可能是从命令行重新启动。

这是我的决赛 persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="MyProject" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/myschema?serverTimezone=UTC"/>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.user" value="root"/>
      <property name="javax.persistence.jdbc.password" value="MyPassword"/>
      <property name="javax.persistence.schema-generation.database.action" value="update"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect" />
    </properties>
  </persistence-unit>
</persistence>

使用 MySQL8 方言是创建表时没有错误的必要条件:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'type=MyISAM' at line 1