Is it possible to use a JPA connection pool with Google App Engine and Cloud SQL?
Asked Answered
F

1

8

(NOTE: Yes, there are some duplicate questions around this topic. However, the ones that are on-point are a few years old... back when Google App Engine only supported JPA 1.0 and the proprietary NoSQL Datastore. It's worth re-visiting now that more contemporary JPA standards and MySQL are supported.)

I am experimenting with Cloud SQL in a Google App Engine Java project, using JPA as the persistence framework. Google's FAQ is somewhat ambivalent about using a connection pool with Cloud SQL... saying it may be worthwhile if the cost of creating a new connection exceeds the cost of checking and reusing an existing connection.

I anticipate that my application will rapidly issue large numbers of very short-lived database operations, so it seems to fit the use case for connection pooling. Moreover, I am **FAR** more concerned about having my connections refused due to a quota cap, than I am about having a request block for a couple of seconds waiting on a connection pool to free up. Based on previous experiences with Google App Engine runtime quotas, I wouldn't even consider Cloud SQL to be a viable service without connection pooling.

The issue is that JPA generally attaches to a connection pool via JNDI, and JNDI is not supported by Google App Engine. How then do people use a connection pool with Google App Engine and Cloud SQL? Is there a way to attach a connection pool to a JPA EntityManagerFactory programmatically, without JNDI? Or do you have to forgo JPA, and write your persistence layer with manual JDBC or some other persistence framework (e.g. JDO)?

To the extent that it matters, I am currently trying to use EclipseLink as the JPA provider and Tomcat DBCP for the connection pooling (I have seen in other StackOverflow questions that Tomcat DBCP works with App Engine's threading restrictions). I am open to exploring other providers or persistence mechanisms (e.g. native Hibernate, JDO, etc)... but I would prefer to stick with JPA standards, and would probably pass on Cloud SQL altogether if it required purely manual JDBC to work with connection pooling.

Filling answered 26/3, 2014 at 15:16 Comment(0)
M
1

I can see this is an old question, but in case anyone ends up here looking for an answer, I use Spring and Apache BasicDataSource on App Engine with Cloud SQL and it works just fine.

Matterhorn answered 11/2, 2015 at 14:16 Comment(1)
Are you using Maven or Eclipse? There doesn't appear to be a pom.xml file in Eclipse where you can add DBCP.Mattern

© 2022 - 2024 — McMap. All rights reserved.