1、只查询需要的数据字段
2、优化数据库往返次数
3、查询只读
Session session = entityManager.unwrap(Session.class);session.setDefaultReadOnly(true);
Listposts = entityManager.createQuery("select p from Post p", Post.class).setHint(QueryHints.HINT_READONLY, true).getResultList();
4、声明批处理
5、使用映射关系
- relationship with JPA and Hibernate
- annotation with JPA and Hibernate
6、数据库级别的处理
7、缓存处理
re details about how to use the Hibernate 2nd-level cache, check out these articles:
8、查询计划缓存
配置Hibernate时另一个鲜为人知的主题是查询计划缓存。 需要解析所有实体查询(例如JPQL或Criteria API)以生成正确的SQL语句。 这个解析实体查询的过程需要时间,因此Hibernate提供了一个计划缓存来重用已经计算的计划。如果您的应用程序生成许多查询,则正确配置查询计划缓存非常重要。 有关更多详细信息,请查看。
参考地址: