Question

I successfully completed the DataNucleus Tutorial for JDO using RDBMS with a local MySQL instance on my Ubuntu 13.10 machine.

While attempting to get the same working on a Google CloudSQL instance, I ran into some problems.

To make the switch, I replaced the following:

<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://127.0.0.1/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>

... with the following:

<property name="javax.jdo.option.ConnectionURL" value="jdbc:google:mysql://<my-project>:nucleus/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.GoogleDriver"/>

I setup the local MySQL and the CloudSQL instances to have the same credentials, so the javax.jdo.option.ConnectionUserName and javax.jdo.option.ConnectionPassword did not need to be changed.

Under the Google Cloud Console Cloud SQL my-project:nucleus MySQL instance, I created a static IP and also whitelisted my development machine's IP address. I verified that I was able to connect natively to it via 'mysql -u root -p -h '.

When I try to run 'mvn datanucleus:schema-create', I get this:

[DEBUG] Exit code: 1
[DEBUG] --------------------
[DEBUG]  Standard output from the DataNucleus tool org.datanucleus.store.schema.SchemaTool :
[DEBUG] --------------------
[INFO] DataNucleus SchemaTool : Creation of the schema
An error was encountered creating a PersistenceManagerFactory : Error creating transactional connection factory - please consult the log for more information.

If I replace the connection settings with the following then it works the same as with the local MySQL instance:

<property name="javax.jdo.option.ConnectionURL" value="jdbc:mysql://<Cloud SQL IP>/nucleus?useServerPrepStmts=false"/>
<property name="javax.jdo.option.ConnectionDriverName" value="com.mysql.jdbc.Driver"/>

So, I've worked around the problem, but why didn't this work with the GoogleDriver? I don't know anything about the black magic that's going on inside that driver, but I'm curious if there was a way to make that work, and whether there's a reason I should use the GoogleDriver at all.

Was it helpful?

Solution

Now that you can use the stock MySQL driver with Cloud SQL, you should use that instead of the older GoogleDriver.

See http://googlecloudplatform.blogspot.com/2013/10/google-cloud-sql-now-accessible-from-any-application-anywhere.html

Hope this helps, Rob

OTHER TIPS

The special Google JDBC driver is for use from Google App Engine applications only. When using it, the CloudSQL instance does not require a static public IP address, which is a billable feature of CloudSQL.

This all becomes obvious after reading the Google CloudSQL docs here and here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top