java + app引擎+ cloudSQL + spring / hibernate

时间:2014-01-06 06:34:46

标签: java google-app-engine google-cloud-datastore google-cloud-sql gae-search

我正在将Spring Hibernate与app engine和cloudSQL一起用于我的项目,但我经常收到一个错误。当应用程序有时变得理想时会发生这种情况。

对于每个查询(获取或保存/更新到数据库),我打开会话并在使用后关闭会话。像这样 - 我的数据库提取代码是

try{ 
        Session session = getSessionFactory().openSession();
        if(session != null)
        {

        List<Account> accounts = session.createQuery("from " + this.clazz.getName() + " where subDomainName = '"+subDomain+"'").list();

        session.close();

        if(accounts != null)
        {
            if(accounts.size()>0){
                return accounts.get(0);
            }
            else{
                return null;
            }
        }
        else
        {
            return null;
        }
        }
        else {
            return null;
        }
        }
        catch(Exception e){
            log.info("Error in retriving subdomain details :: in Account Dao");
            return null;

        }

我使用的是Autowired结构。但是当应用程序在某个时候变得理想时,在刷新页面的某个时间之后,它会在应用程序引擎上显示错误为Stream Closed of CloudSQL,错误如下所示...

错误是:

6 Jan, 2014 6:21:04 AM com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse
WARNING: Authentication error: Unable to respond to any of these challenges: {bearer=WWW-Authenticate: Bearer realm="https://www.google.com/accounts/AuthSubRequest", error=invalid_token}
6 Jan, 2014 6:21:04 AM com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver openConnection
WARNING: openConnection
java.sql.SQLException: Stream closed
    at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.newOpenConnectionIOException(RpcGoogleApi.java:187)
    at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:105)
    at com.google.appengine.api.rdbms.dev.LocalRdbmsServiceRemoteDriver.openConnection(LocalRdbmsServiceRemoteDriver.java:206)
    at com.google.appengine.api.rdbms.dev.LocalRdbmsService.openConnection(LocalRdbmsService.java:119)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.callInternal(ApiProxyLocalImpl.java:498)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:452)
    at com.google.appengine.tools.development.ApiProxyLocalImpl$AsyncApiCall.call(ApiProxyLocalImpl.java:430)
    at java.util.concurrent.Executors$PrivilegedCallable$1.run(Executors.java:461)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.util.concurrent.Executors$PrivilegedCallable.call(Executors.java:458)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.IOException: Stream closed
    at java.util.zip.GZIPInputStream.ensureOpen(GZIPInputStream.java:42)
    at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:85)

为了吸引应用程序引擎和cloudSQL我已经确定了某些请求的cron工作,但这不是可行的解决方案,我无法理解为什么cloudSQL关闭它的应用程序引擎流。

0 个答案:

没有答案