我有一个非常简单的查询来从表中选择所有行。在 hibernate 状态下,它总是需要大约 17-18 秒。我指定 show_sql
为真。我直接把sql命令复制到mysql中用了0.00022秒...
这是查询:
SELECT
organizati0_.id AS id1_5_,
organizati0_.adminList AS adminLis2_5_,
organizati0_.demoAccount AS demoAcco3_5_,
organizati0_.disabled AS disabled4_5_,
organizati0_.enduserCredits AS enduserC5_5_,
organizati0_.name AS name6_5_,
organizati0_.pushNotificationRoom AS pushNoti7_5_,
organizati0_.totalLicenses AS totalLic8_5_,
organizati0_.usedLicenses AS usedLice9_5_
FROM
organization organizati0_
这是查询的代码:
Session session = ThreadSessionHolder.getThreadSession();
Query query = session.createQuery("from Organization ");
List list = query.list();
return list;
有什么想法吗?这让我抓狂
最佳答案
我发现了问题。
我正在构造函数中执行初始化操作,在选择所有时不应该这样做
关于java - sql 查询在 Hibernate 中很慢,在 mysql 上很快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228522/