在我的spring应用程序中,lazy fetch不起作用,这使得db中的fetch操作很繁重。所以,当我招学生的时候,就是迫不及待地招那些甚至被标记为懒惰的领域。我的班是学生班
class Student{
Long id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
@JoinColumn(name = "tutor_fk", nullable = false)
Tutor tutor;
@OneToMany(fetch = FetchType.LAZY, mappedBy = Courses.student, cascade = CascadeType.ALL)
Set<Courses> courses = new HashSet<>();
}
课程.班级
class Courses{
Long id;
String create_date_time;
@ManyToOne
@JoinColumn(name = "student_fk")
Student student;
}
辅导班
class Tutor{
Long id;
String name;
}
学生服务.class
@Transactional
class studentService{
List<Students> getStudent(Long id){
return studentRepository.findOneById(id);
} }
当我在org.hibernate.sql上运行代码时:debug。查询命中率
select course0_.id as id1_43_0_, course0_.create_date_time as create_date_time2_43_0_
from course course0_ where course0_.id=?
select tutor0_.id as id1_43_0_, tutor0_.name as name2_43_0_
from tutor tutor0_ where tutor0_.id=?
我做错了,当这些字段被标记为lazy时,它将上述查询作为earge
暂无答案!
目前还没有任何答案,快来回答吧!