使用休眠从 Google App Engine 连接到 Google SQL

Connect to Google SQL from Google App Engine using hibernate

我正在尝试从 google 云 sql 连接到我的数据库 使用休眠,但出现以下错误...

Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.mysql.jdbc.GoogleDriver

但我在 pom.xml

中有依赖关系
<dependency>
     <groupId>mysql</groupId>
     <artifactId>mysql-connector-java</artifactId>
     <version>5.1.38</version>
</dependency>

我这样调用createEntityManagerFactory...

    Map<String, String> properties = new HashMap<>();

    properties.put("javax.persistence.jdbc.driver",
            "com.mysql.jdbc.GoogleDriver");
    properties.put("javax.persistence.jdbc.url",
            System.getProperty("cloudsql.url"));

    EntityManagerFactory emf = Persistence.createEntityManagerFactory(
            "Test", properties);

有人可以帮助我吗?谢谢

您需要在 appengine-web.xml 中输入以下内容:

<use-google-connector-j>true</use-google-connector-j>