app引擎的hibernate配置

时间:2014-08-06 11:05:27

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

如何配置hibernate.cfg.xml以访问云sql以及本地mysql实例? 以下代码在JDBC中工作,我需要在hibernate中进行这样的配置。

if (SystemProperty.environment.value() ==
          SystemProperty.Environment.Value.Production) {
        // Load the class that provides the new "jdbc:google:mysql://" prefix.
        Class.forName("com.mysql.jdbc.GoogleDriver");
        url = "jdbc:google:mysql://your-project-id:your-instance-name/guestbook?user=root";
      } else {
        // Local MySQL instance to use during development.
        Class.forName("com.mysql.jdbc.Driver");
        url = "jdbc:mysql://127.0.0.1:3306/guestbook?user=root";

        // Alternatively, connect to a Google Cloud SQL instance using:
        // jdbc:mysql://ip-address-of-google-cloud-sql-instance:3306/guestbook?user=root
      }

1 个答案:

答案 0 :(得分:1)

我建议您查看how to use JPA-based ORM libs with Cloud SQL上的官方文档。