(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.)
(注意:是的,围绕这个主题有一些重复的问题。但是,那些在点上的问题已经存在几年......当Google App Engine仅支持JPA 1.0和专有的NoSQL数据存储时。现在访问,支持更现代的JPA标准和MySQL。)
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.
我正在使用JPA作为持久性框架在Google App Engine Java项目中试验Cloud SQL。谷歌的常见问题解答在使用与云端SQL的连接池时有点矛盾......如果创建新连接的成本超过检查和重用现有连接的成本,那么这可能是值得的。
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.
我预计我的应用程序将迅速发布大量非常短暂的数据库操作,因此它似乎适合连接池的用例。此外,我是** FAR **更担心由于配额上限而拒绝我的连接,而不是我在一个等待连接池释放的请求阻塞几秒钟。根据以前使用Google App Engine运行时配额的经验,我甚至不认为Cloud SQL是没有连接池的可行服务。
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)?
问题是JPA通常通过JNDI连接到连接池,而Google App Engine不支持JNDI。那么人们如何使用与Google App Engine和Cloud SQL的连接池?有没有办法以编程方式将连接池连接到JPA EntityManagerFactory,而没有JNDI?或者您是否必须放弃JPA,并使用手动JDBC或其他一些持久性框架(例如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 * 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.
在重要的程度上,我目前正在尝试使用EclipseLink作为JPA提供程序,使用Tomcat DBCP作为连接池(我已经在其他*问题中看到Tomcat DBCP与App Engine的线程限制一起使用)。我愿意探索其他提供者或持久性机制(例如本机Hibernate,JDO等)......但我更愿意坚持使用JPA标准,并且如果它需要纯手工JDBC来处理连接,它可能会完全传递Cloud SQL池。
1 个解决方案
#1
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.
我可以看到这是一个老问题,但是如果有人最终在这里寻找答案,我在App Engine上使用Spring和Apache BasicDataSource和Cloud SQL,它运行得很好。
#1
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.
我可以看到这是一个老问题,但是如果有人最终在这里寻找答案,我在App Engine上使用Spring和Apache BasicDataSource和Cloud SQL,它运行得很好。