-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: EntityManager gracefully handle database restart?
PostPosted: Thu Dec 02, 2010 10:55 am 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
In my servlet based webapp, I use the hibernate 3.5.0.Beta-1 EntityManager to access a postgres db. Sometimes the postgres db needs to be restarted. Whenever this happens the next query from my EntityManager fails like this:

Quote:
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2235)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:411)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1083)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:93)
... 39 more
Caused by: org.postgresql.util.PSQLException: An I/O error occured while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:218)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:451)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:350)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:254)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1812)
at org.hibernate.loader.Loader.doQuery(Loader.java:697)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
... 47 more
Caused by: java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:26)
at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:121)
at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:212)
at org.postgresql.core.PGStream.flush(PGStream.java:507)
at org.postgresql.core.v3.QueryExecutorImpl.sendSync(QueryExecutorImpl.java:676)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:191)
... 55 more


What is the best practice for gracefully handling database restarts like this?


Top
 Profile  
 
 Post subject: Re: EntityManager gracefully handle database restart?
PostPosted: Tue Dec 07, 2010 1:00 pm 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
Hi Guys,

Does any one have any suggestions on my question. Please let me know if I was not clear in my post. Thanks.


Top
 Profile  
 
 Post subject: Re: EntityManager gracefully handle database restart?
PostPosted: Wed Dec 08, 2010 6:19 pm 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
farrukh_najmi wrote:
Hi Guys,

Does any one have any suggestions on my question. Please let me know if I was not clear in my post. Thanks.


I have tried adding logic to detect that PersistenceException is caused by a JDBCConnectionException and if so creating a new EntityManager to use for my query.
This does not seem to work either. The retried query using the new EntityManager gives the same PersistenceException is caused by a JDBCConnectionException. I have validated in debugger that the retry is done with a newly created EntityManager.

So my rephrased question is... How do I use force hibernate layer to create a new connection to the database if a newly created EntityManager does not do the trick? Where in hibernate layers is the connection to the database made?

I assume this is something many people before me have needed to do so please share your experience. Thanks.


Top
 Profile  
 
 Post subject: [Solved] EntityManager gracefully handle database restart?
PostPosted: Wed Dec 08, 2010 6:59 pm 
Newbie

Joined: Thu Sep 14, 2006 12:08 pm
Posts: 19
I finally figured it out. To handle db restart gracefully I needed to recreate a new EntityManagerFactory and then use it to create new EntityManagers. Previously I was only creating new EntityManagers but the connection to db was cached somewhere in the EntityManagerFactory. HTH other folks. I must say I am surprised by the lack of help from the community. Was it because my question was so dumb and answer so obvious?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.