This week i tried to use
Hibernate 4.3.6.Final in a
Google App Engine / Google Cloud Sql project and ran into a problem;
When starting up, Hibernate throws
Quote:
java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)
In earlier GAE/GCS projects i used Hibernate 4.3.0.Beta3 without any problems (
with connection.pool_size = 0). The problem is the new implementation of the default connection pool
DriverManagerConnectionProviderImpl in Hibernate. This connection pool tries to spawn new Threads with
Executors.newSingleThreadScheduledExecutor;
Code:
executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleWithFixedDelay(
new Runnable() {...}
This is not allowed on Google App Engine;
This is not allowed on Google App Engine;
https://cloud.google.com/appengine/docs/java/
Quote:
A GAE Java application can create a new thread, but there are some restrictions on how to do it. These threads can't "outlive" the request that creates them.
The actual problem is the Hibernate configuration which doesn't allow the use of no connection pool. According to Google this connection pool is even not necessary on GAE/GCS;
https://cloud.google.com/sql/faq#connections
Quote:
How to best manage your database connections depends on your use case. For example, if the time to create a new database connection is greater than checking and reusing an existing connection, then we recommend you use connection pooling. Conversely, if the time to create a new connection is about the same as testing if an existing connection is alive and reusing it, then we recommend that you create a new connection to service each HTTP request, and reuse it for the duration of the request. In particular, the latter case may apply when you connect from Google App Engine to Google Cloud SQL.
summarized; we don't need connection pooling on GAE/GCS, but Hibernate doesn't provide a non connection pooling option out of the box.Because of a tight schedule i went for a quick solution; i wrote my own version of DriverManagerConnectionProviderImpl. This version doesn't keep a administration of connections but just opens and closes connection on a call. There's some room for improvement because i should reuse the connection for the duration of the request ... Another solution would be the use of approved GAE Threads...
In my opinion Hibernate should provide the no pooling option for GAE/GCS developers...