java - JPA 属性表达式与使用“In”
问题描述
我有 3 节课:
学院:
id, name, ....
学生:
id, name, college, ....
标记:
id, subject, student
我有collegeObject和学生名单。我可以通过两种方式查询学生的分数:
JPA 属性表达式:
List<Marks> findByStudentCollege(College college)
.
在查询中使用
List<Marks> findByStudentIn(Set<Student> studentList)
从性能的角度来看,我需要帮助来了解哪个查询更适合使用。
解决方案
您正在执行两个不同的查询:
findByStudentCollege(College college) :这个将用于在“college”中的每个元素“student”中查找大学的分数。你没有在分数和大学之间建立联系,所以你可能会做一个查询,比如“select * from tags where student = (Select id from Student where college = (select from College))
findByStudentIn(Set studentList) :这个将用于查找列表中的分数(0个或多个“学生”元素,因此您需要在之前列出学生,或者使用它来查找焦点学生的分数。
如果您没有完整的学生名单,第二个可能是最好的选择。如果您让一所大学的所有学生使用第一个,因为您正在避免第一个学生列表。
无论如何,即使您使用 5k+ 行,您也不会看到这些查询之间的区别
推荐阅读
- java - 为什么在 Java 中的 2D / 3D 数组中需要行大小而列大小是可选的?
- java - 有没有办法启动只通过 API 定义一次的 Kafka 侦听器的多个线程?
- visual-studio-2019 - 如何使用 clickonce .net core 3.1 创建多个桌面快捷方式?
- events - 事件和中断之间的区别
- amazon-web-services - 使用脚本为现有 SQS 队列创建警报
- node.js - firebase googleapis 未验证 nodejs 的令牌
- c++ - 运行时检查失败 #2 - 变量“array1”周围的堆栈已损坏
- javascript - 在 JavaScript 函数中添加动态属性
- c# - 使用 Entity Framework Code First 向表和列添加扩展属性
- ios - 如何修复文档警告 Xcode