Hello I am using dropwizard and hibernate in my application and have written the following heakthcheck. This gives me a
org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ResultSet is from UPDATE. No Data. error
I tried changing the .getResultList()
call to executeUpdate()
getMaxResults()
, list()
but none of them work. How can I make a SELECT query work in a healthcheck?
public class DatabaseHealthCheck extends HealthCheck {
SessionFactory sessionFactory;
private static final String validationQuery =
"SELECT table_name FROM information_schema.tables WHERE table_schema = 'mySchema'";
public DatabaseHealthCheck(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
@Override
protected Result check() throws Exception {
Session session = sessionFactory.openSession();
final Transaction txn = session.beginTransaction();
try {
EntityManager em = session.getEntityManagerFactory().createEntityManager();
em.createNativeQuery(validationQuery).getResultList();
txn.commit();
} catch (Exception e) {
txn.rollback();
return Result.unhealthy("Cannot execute query due to " + e.getMessage());
} finally {
session.close();
}
return Result.healthy();
}
}
I also tried making the query simpler - 'SELECT1 ' but still see the same error