I am using Spring Hibernate with app engine and cloudSQL for my project but i am getting one error frequently. This occurs when application becomes ideal for sometimes.
For every query (fetching or save/update to database), i open session and close session after its use. like this --
My code for database fetching is
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;
}
I am using Autowired structuring. but when application becomes ideal for sometime and after some time when i refresh page its display the error as Stream Closed of CloudSQL on app engine, error is shown below...
Error is :
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)
For this to engage app engine and cloudSQL i have wriiten cron job of certains request but this is not feasible solution, i can not gets why cloudSQL closes its stream for app engine.
Related
Yesterday from Crashlytics I noticed disk I/O error (code 522) while opening the database. Problem is that this crashed already has been reported from 16 users 36 times. Sadly I can't reproduce this error. Here's the code fragment where error occurs
SessionDbManager(Context context, String tripDbFileName) {
this.context = context;
this.tripDbFileName = tripDbFileName;
this.tripDbHelper = new SessionDbHelper(this.context, tripDbFileName);
SQLiteDatabase database = null;
int attempt = 1;
while (database == null) {
try {
database = this.tripDbHelper.getWritableDatabase(); // here's the error
} catch (android.database.sqlite.SQLiteException e) {
Crashlytics.logException(e);
XLog.e("Failed to load history data from database ", e);
if (attempt == 5) throw e;
}
attempt++;
}
db = database;
}
And here's the stack trace
Fatal Exception: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522): , while compiling: PRAGMA journal_mode
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:932)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:677)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:363)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:337)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:251)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:195)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:737)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:289)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at eu.fishingapp.data.sql.session.SessionDbManager.(SourceFile:51)
at eu.fishingapp.data.sql.session.SessionContentProvider.update(SourceFile:753)
at android.content.ContentProvider$Transport.update(ContentProvider.java:384)
at android.content.ContentResolver.update(ContentResolver.java:1412)
at eu.fishingapp.data.sql.session.SessionDbHelper.renameSessionDb(SourceFile:584)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadFile(SourceFile:462)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessions(SourceFile:221)
at eu.fishingapp.data.network.synchronization.FileSyncServiceImpl.uploadSessionsFiles(SourceFile:243)
at eu.fishingapp.data.network.synchronization.FileSyncIntentService.onHandleIntent(SourceFile:116)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:67)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
I have read about I/O error and found two possible answers I was thinking that this is because users ran out of free space on their devices. But here's some images from two app users
So this is definitely not storage issue :( Any ideas how to solve this problem?
EDIT: targetSdk version 22
I am developing a project using Eclipse Java EE, Maven and Geotools. This is the part of the code that I am going to talk about:
Map connectionParameters = new HashMap();
// Connection parameters
connectionParameters.put(WFSDataStoreFactory.URL.key, getCapabilities );
connectionParameters.put(WFSDataStoreFactory.PROTOCOL.key, false );
connectionParameters.put(WFSDataStoreFactory.LENIENT.key, true );
connectionParameters.put(WFSDataStoreFactory.MAXFEATURES.key, 30);
connectionParameters.put(WFSDataStoreFactory.TIMEOUT.key, 600000);
try { // The WFSDataStoreFactory dsf is already created before
WFSDataStore dataStore = dsf.createDataStore(connectionParameters);
// We get the source and then the features from it
SimpleFeatureSource source = dataStore.getFeatureSource("gmgml_AREAOBRA");
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures();
// We try to go one by one and print to see if it really exists
while(fc.features().hasNext()){
SimpleFeature sf = fc.features().next();
System.out.println(sf.getAttribute("IDOBRA")); } // It crashes
The thing is that I read every post about the next error that gives me after crashing:
> SEVERE: Failed to execute request http://mapa20.ewise.es/WFS_EGIOS_SITUATIONROOM/
service.svc/get?TYPENAME=gmgml%3AAREAOBRA&REQUEST=GetFeature&OUTPUTFORMAT=text%2
Fxml%3B+subtype%3Dgml%2F3.1.1&VERSION=1.1.0&SERVICE=WFS
java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:176)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:58)
at com.sitep.imi.acefat.server.daemon.InsertarBBDDDaemon.dataAccess(InsertarBBD
DDaemon.java:229)
at com.sitep.imi.acefat.server.daemon.InsertarBBDDDaemon.insertData(InsertarBBD
DDaemon.java:98)
at com.sitep.imi.acefat.App.main(App.java:17)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:704)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnectio
n.java:1535)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:1440)
at org.geotools.data.ows.SimpleHttpClient$SimpleHTTPResponse.<init>(SimpleHttpC
lient.java:171)
at org.geotools.data.ows.SimpleHttpClient.get(SimpleHttpClient.java:102)
at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOp
enWebService.java:426)
at org.geotools.data.wfs.internal.WFSClient.internalIssueRequest(WFSClient.java
:286)
at org.geotools.data.wfs.internal.WFSClient.issueRequest(WFSClient.java:326)
at org.geotools.data.wfs.WFSFeatureSource.getReaderInternal(WFSFeatureSource.ja
va:256)
at org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.
java:634)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureColl
ection.java:173)
But I cannot find a specific answer for my problem.
I tried to create a lotus notes client using Java. Now, I have a problem to list all the user defined databases. What I tried to do is
// testing purpose
private void printAllDb() throws NotesException
{
DbDirectory dir = session.getDbDirectory(host);
String server = dir.getName();
if(server.equals(""))
{
server = "Local";
}
System.out.println("database direcory list on server (" + server + ")");
Database db = dir.getFirstDatabase(DbDirectory.DATABASE);
do
{
System.out.println("file name: " + db.getFileName().toUpperCase() + " - " + db.getTitle());
} while((db = dir.getNextDatabase()) != null);
}
However, the program will throw the exception:
Exception in thread "main" NotesException: Server access denied
at lotus.domino.NotesExceptionHelper.read(Unknown Source)
at lotus.domino.NotesExceptionHolder._read(Unknown Source)
at lotus.priv.CORBA.iiop.RepImpl.invoke(Unknown Source)
at lotus.priv.CORBA.portable.ObjectImpl._invoke(Unknown Source)
at lotus.domino.corba._IDbDirectoryStub.getFirstDatabase(Unknown Source)
at lotus.domino.cso.DbDirectory.getFirstDatabase(Unknown Source)
at nz.co.sylresearch.sylsearch.agents.lotusnotes.LotusNotesAPIHandler.printAllDb(LotusNotesAPIHandler.java:58)
at nz.co.sylresearch.sylsearch.agents.lotusnotes.LotusNotesAPIHandler.main(LotusNotesAPIHandler.java:44)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
The issue is pretty clear. You are getting an access denied error to the server. The tricky part now is figuring out why.
You should start with making sure the username and password used to create the session object is correct. Then make sure that user has access to the server and has access to run Java code on the server. You'll have to check the server document in the Directory for that.
I am trying to access to an URL using WS on Play Framework 2.1 using JAVA api.
Here is what I want:
Some where in the code, start a WS request using WS.get() (I set timeout 1000ms)
If WS.get times out or another exception happens, I don't want my Promise throw an exception (since my flow reqiures it that way) So I use Promise.recover() to wrap that promise with another. Which returns a null Reponse object in case of failures.
Some where else in code I want to "get" my Response. I wait for 5000ms but what I get is java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]
How? WS.get() timesout after 1000ms and since it throws an java.util.concurrent.TimeoutException: No response received after 1000 it is catched by my recover function. It returns a null response instead of an exception.
So promise is "completed" after 1000ms at most. Why it times out and throws an exception after 5000 ms?
Code:
Logger.info("Fetch started: " + new Date().toString());
Promise<WS.Response> p1 = WS.url("http://athena.ics.forth.gr:9090/RDF/VRP/Examples/tap.rdf").setTimeout(1000).get();
Promise<WS.Response> p2 = p1.recover(new Function<Throwable, WS.Response>() {
#Override
public Response apply(Throwable a) throws Throwable {
Logger.error("Promise thrown an exception so I will return null. " + new Date().toString() + " " + System.currentTimeMillis(), a);
return null;
}
});
try {
/* This should return null or valid response but shouldn't throw an exception */
Response r = p2.get(5000L);
Logger.info(r.toString());
} catch (Exception e) {
/* Sholdn't happen! */
Logger.error("Outer exception: " + " " + System.currentTimeMillis(), e);
}
Logger.error("Fetch finished: " + new Date().toString() + " " + System.currentTimeMillis());
Output I get:
[info] application - Fetch started: Tue Mar 19 10:04:42 EET 2013
[error] application - Outer exception: 1363680287626
java.util.concurrent.TimeoutException: Futures timed out after [5000 milliseconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:96) ~[scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:58) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at scala.concurrent.Await$$anonfun$ready$1.apply(package.scala:86) ~[scala-library.jar:na]
at akka.dispatch.MonitorableThreadFactory$AkkaForkJoinWorkerThread$$anon$3.block(ThreadPoolBuilder.scala:173) ~[akka-actor_2.10.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.managedBlock(ForkJoinPool.java:2803) [scala-library.jar:na]
[error] application - Fetch finished: Tue Mar 19 10:04:47 EET 2013 1363680287627
[error] application - Promise thrown an exception so I will return null. Tue Mar 19 10:04:47 EET 2013 1363680287627
java.util.concurrent.TimeoutException: No response received after 1000
at com.ning.http.client.providers.netty.NettyAsyncHttpProvider$ReaperFuture.run(NettyAsyncHttpProvider.java:1809) ~[async-http-client.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_11]
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351) ~[na:1.7.0_11]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178) ~[na:1.7.0_11]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) ~[na:1.7.0_11]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[na:1.7.0_11]
Even I wait for promise2 and promise2 is "recover wrapped promise1" recover function runs AFTER exception is thrown.
Okay, i am very very very new to Hibernate/Spring. I had to upgrade existing code from Hibernate 2 - Hibernate 4 and Spring 1 - Spring 3.
I keep getting this exception when trying to call saveOrUpdate when passing more than one message to the database (it works fine when I only send one message):
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session
at org.hibernate.engine.internal.StatefulPersistenceContext.checkUniqueness(StatefulPersistenceContext.java:686)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performUpdate(DefaultSaveOrUpdateEventListener.java:293)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:239)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:109)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:728)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:720)
at org.hibernate.engine.spi.CascadingAction$5.cascade(CascadingAction.java:258)
at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:380)
at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:323)
at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:208)
at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:165)
at org.hibernate.event.internal.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:423)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:264)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:136)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:114)
at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:728)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:720)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:716)
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 org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:352)
at $Proxy9.saveOrUpdate(Unknown Source)
I have googled till I am blue in the face! I have tried to use merge(). This does not give the exception, but merge inserts NULL values into the Database.
I have tried to use evict(), flush(), same error.
This is the method that causes the error:
public void saveOrUpdate(Object obj) {
Session session = null;
SessionFactory sf = getSessionFactory();
try {
try {
session = sf.getCurrentSession();
} catch (Exception e) {
session = sf.openSession();
}
System.out.println("Object: " + obj);
session.beginTransaction();
session.saveOrUpdate(obj);
session.getTransaction().commit();
System.out.println("DONE");
} catch (Exception e) {
e.printStackTrace();
}
}
Any help would be greatly appreciated!
Can you please provide the mappings and the code which calls the saveOrUpdate methods. It looks like the error is in the code which calls the saveOrUpdate
I solved it :)
I don't know if its the best solution, but it works for me and after 2 solid days of struggling I'm happy!
I removed Cascade from the parent object and explicitly called saveOrUpdate on parent and then on the children.
Thanks everyone for the help :)