My Quotes


When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY






Wednesday, February 6, 2013

Caused by: java.sql.SQLException: Io exception: Got minus one from a read call


I was struggling with the following exception for couple of days and here is my fix
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not open connection


Caused by: java.sql.SQLException: Io exception: Got minus one from a read call



Make sure that you DO NO SPAN a transaction in any of the READ methods.
entitymanager.getTransaction().begin()

If so ensure that before you call the  entitymanager.close(), do a 
entitymanager.getTransaction().commit().

This might prove costly because of the COMMIT. But on the contrary if you do not commit / rollback, then the transaction will be OPEN
and trying to close the EntityManager will not close the EM since
em.getTransaction().isActive() is true.

so these connections will be open causing the avbove said exception over a period of time.

So better the choice of execution order would be

try{
     getEntityManager()
       READ
}catch(Exception ){ do something}
  finally{
    em.close();
}


One last thing, closing the EMF will actually close the connection pool.

I really liked this website giving more insight and information about JPA





No comments :