database - Dropwizard 数据库运行状况检查中的 SELECT 查询
问题描述
您好,我在我的应用程序中使用 dropwizard 和 hibernate 并编写了以下 heakthcheck。这给了我一个
org.hibernate.engine.jdbc.spi.SqlExceptionHelper: ResultSet is from UPDATE. No Data. error
我尝试将.getResultList()
呼叫更改为executeUpdate()
getMaxResults()
,list()
但它们都不起作用。如何使 SELECT 查询在运行状况检查中工作?
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();
}
}
我还尝试使查询更简单 - 'SELECT1' 但仍然看到相同的错误
解决方案
推荐阅读
- autoencoder - 为什么 VAE 的 z 变量的分布不在 -1 和 1 之间?
- docker - 在 192.168.65.5:53 上查找:没有这样的主机
- oracle - 在 oracle 报告中执行获取结果错误
- spring-boot - Gradle 找不到插件,使用 Spring 初始化程序初始化的 Spring Boot 项目
- javascript - 导出已在导出函数中使用的变量
- asp.net-web-api - 哪种 Insights 实施可以保证记录所有异常?
- java - 默认情况下使用依赖项启用 Spring 自动配置
- r - 如何为绘图中曲线下的区域着色
- angular - 无法以角度访问子组件的第二级
- c - 这个关于指针运算符的陈述是什么意思?"& 只能与变量一起使用,* 可以与变量、常量或表达式一起使用。"