w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
connection gone out while scheduled operation in Spring with BoneCP: "Database access prob lem. Killing off this connection..."

That's because you don't ever close the EntityManager and the associated connections might hang indefinitely.

Change your code to this instead:

EntityManager em = null;
try {        
    em = entityManagerFactory.createEntityManager();
    em.getTransaction().begin();
    rows = em.createNativeQuery("UPDATE table SET ...").executeUpdate();
    em.getTransaction().commit();
} catch (Exception ex) {
    logger.error("Exception while scheduledOperation. Details: " +
ex.getMessage());
    em.getTransaction().rollback();
} finally {
    if(em != null) {
        em.close();
    }
}

And always call rollback on failure. Don't assume transactions will rollback automatically because this is a database specific implementation.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.