我在使用 Criteria 和 left join 时遇到了性能问题。以下是我的查询:
Criteria crit = session.createCriteria(CuttingAssignment.class);
crit.add(Restrictions.eq("cuttingMachine", cuttingMachine));
crit.createAlias("cuttingBatch", "cuttingBatch");
crit.addOrder(Order.asc("psn"));
crit.setFetchMode("cuttingBatch", FetchMode.JOIN);
crit.setFetchMode("cuttingMachine", FetchMode.JOIN);
crit.createAlias("cuttingBatch.isolatingBatches", "cuttingBatch.isolatingBatches", Criteria.LEFT_JOIN);
crit.createAlias("cuttingBatch.isolatingBatches.assignments", "cuttingBatch.isolatingBatches.assignments", Criteria.LEFT_JOIN);
crit.createAlias("cuttingBatch.articleType", "cuttingBatch.articleType");
crit.setFetchMode("cuttingBatch.articleType", FetchMode.JOIN);
crit.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
List<CuttingAssignment> cuttingAssignmentList = crit.list();
现在它将在数据库中执行这么多的 sql 查询,因为我面临性能问题?
优化 Criteria Query 的方法有哪些?条件和 HQL 查询之间有什么区别吗?
提前致谢。