使用hibernate从Google App Engine连接到Google SQL

时间:2016-01-28 16:46:42

标签: hibernate google-app-engine google-cloud-sql

我正在尝试从google cloud sql连接到我的数据库 使用hibernate,但是我收到以下错误...

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);

有人可以帮助我吗?感谢

1 个答案:

答案 0 :(得分:1)

您需要将以下内容放入appengine-web.xml

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