2

I started learning about the google cloud platform and I have been able to create a project and an instance and then I created a db using a mysql dump file. Now, I have this application which was created using hibernate and it works when the db is pointing to my local mysql workbench, but when I change the url to this:

jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&password=${password}

it keeps giving this error:

[INFO] GCLOUD: javax.persistence.PersistenceException: Unable to build entity manager factory
[INFO] GCLOUD:  at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
[INFO] GCLOUD: Caused by: org.hibernate.HibernateException: Unable to make JDBC Connection [jdbc:google:mysql://${INSTANCE_CONNECTION_NAME}/${database}?user=${user}&password=${password}]
[INFO] GCLOUD:  at org.hibernate.engine.jdbc.connections.internal.BasicConnectionCreator.createConnection(BasicConnectionCreator.java:60)

I have my persistence.xml file, web.xml file and appengine-web.xml file in the right places and when I try the api using postman, it takes a few seconds before returning the error, which makes me think it does hit the url but maybe the endpoint is refusing the connection? I'm not sure what I am doing wrong. I need a point in the right direction, if anyone can. My main goal is to set up the endpoints which can be queried to return data from the database.

Aria
  • 389
  • 3
  • 7
  • 25
  • You're not trying to connect there from the computer you're writing code on, are you? – Kayaman Jan 08 '18 at 16:24
  • @kayaman you mean if I'm using multiple computers? No? I'm using the same computer I'm writing code with to test this – Aria Jan 08 '18 at 16:26
  • So you **are** trying to connect there from the computer you're writing code on. Databases (or other similar resources) aren't generally opened to the outside world for security purposes. That's why you can't connect. – Kayaman Jan 08 '18 at 16:28
  • I am not aware of this. I have not had that problem while using heroku :/ so what do you suggest? I have just one system so I'm not sure how else I can do this. – Aria Jan 08 '18 at 16:32
  • Use a local db for development or make an SSH tunnel to allow access to the cloud db? – Kayaman Jan 08 '18 at 16:35
  • oh wait, this is actually running on my localhost, I am just trying to test the endpoint by hitting the database in the google cloud sql..is that okay? – Aria Jan 08 '18 at 16:37
  • No it's not okay, because you didn't understand a word I said. You can't access the database in the cloud from your computer because of security reasons. – Kayaman Jan 08 '18 at 16:38
  • Okay, I think I understand now. I found this [article](https://support.cloud.engineyard.com/hc/en-us/articles/205408088-Access-Your-Database-Remotely-Through-an-SSH-Tunnel) so ill try it out and let you know if that works – Aria Jan 08 '18 at 16:43
  • Or maybe not, [this documentation](https://cloud.google.com/solutions/mysql-remote-access) would imply that cloud instances do have a public IP. Not too familiar with Google's cloud environment, so don't know how it's handled there. – Kayaman Jan 08 '18 at 16:44
  • There is actually no issue with accessing your Cloud SQL instance from any external application, as far as you set up everything properly. Have a look at [this documentation page](https://cloud.google.com/sql/docs/mysql/connect-external-app#before_you_start), I think it can be a good place to start. – dsesto Jan 09 '18 at 11:55

0 Answers0