This week, I tried using Hibernate 4.3.6.Final in the Google App Engine / Google Cloud Sql project and ran into the problem described above ( java.security.AccessControlException ). In previous GAE / GCS projects, I used Hibernate 4.3.0.Beta3 without any problems.
As Gaël Oberson previously pointed out, the problem is the new implementation of the default connection pool DriverManagerConnectionProviderImpl in Hibernate. This connection pool is trying to create new threads using Executors.newSingleThreadScheduledExecutor ;
executorService = Executors.newSingleThreadScheduledExecutor(); executorService.scheduleWithFixedDelay( new Runnable() {...}
This is not allowed in the Google App Engine;
A Java application can create a new thread, but there are some restrictions on how to do this. These threads cannot survive the request that creates them.
The real problem is the Hibernate configuration, which does not allow the use of a connection pool . According to Google, this connection pool is not even needed in GAE / GCS ;
How best to manage database connections depends on your use case. For example, if the time to create a new database connection is less than checking and reusing an existing connection, then we recommend using a connection pool. Conversely, if the time to create a new connection is about the same as testing, if the existing connection is live and reused, then we recommend that you create a new connection to serve 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 do not need a connection pool in GAE / GCS, but Hibernate does not provide the ability to pool without a connection.
Due to the limited schedule, I went for a quick fix; I wrote my own version of DriverManagerConnectionProviderImpl. This version does not support connection administration, but simply opens and closes the connection when called. There is room for improvement because I have to reuse the connection for the entire duration of the request ... Another solution would be to use approved GAE streams ...
In my opinion, Hibernate should provide an opportunity to unite without the participation of GAE / GCS developers. I have already posted this thread in the Hibernate community .