【问题标题】:Connect to Google SQL from Google App Engine using hibernate使用休眠从 Google App Engine 连接到 Google SQL
【发布时间】:2016-05-06 03:59:03
【问题描述】:

我正在尝试从 google cloud 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);

有人可以帮我吗?谢谢

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 确保它也在已部署的版本上声明
    • 我通过更改休眠版本解决了。现在我正在使用 4.2.0.Final 并且可以正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-17
    • 2020-06-07
    • 2019-11-27
    • 2015-09-15
    • 2019-01-27
    • 1970-01-01
    相关资源
    最近更新 更多