package dao.domain;public class Student { public int id; public String name; public int teacher_id; public Teacher teacher; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getTeacher_id() { return teacher_id; } public void setTeacher_id(int teacher_id) { this.teacher_id = teacher_id; } public Teacher getTeacher() { return teacher; } public void setTeacher(Teacher teacher) { this.teacher = teacher; }}
2.Teacher.java
package dao.domain;public class Teacher { public int id; public String name; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
3.StudentDAO.java
package dao;import dao.domain.Student;public interface StudentDAO { public Student getStudentByID(int id);}
import dao.StudentDAO;import dao.domain.Student;import dao.impl.StudentDaoImpl;public class Test { public static void main(String[] args) { StudentDAO dao = new StudentDaoImpl(); Student article = dao.getStudentByID(1); System.out.println(article.getTeacher().getName()); }}
Thread [main] (Suspended (breakpoint at line 61 in CglibProxyFactory)) CglibProxyFactory.createProxy(Object, ResultLoaderMap, Configuration, ObjectFactory, List >, List
Thread [main] (Suspended (breakpoint at line 143 in CglibProxyFactory$EnhancedResultObjectProxyImpl)) owns: ResultLoaderMap (id=38) CglibProxyFactory$EnhancedResultObjectProxyImpl.intercept(Object, Method, Object[], MethodProxy) line: 143 Student$$EnhancerByCGLIB$$e1afda28.getTeacher() line: not available Test.main(String[]) line: 10
代码执行到了如下地方:
if (lazyLoader.size() > 0 && !FINALIZE_METHOD.equals(methodName)) { if (aggressive || lazyLoadTriggerMethods.contains(methodName)) { lazyLoader.loadAll(); } else if (PropertyNamer.isProperty(methodName)) { final String property = PropertyNamer.methodToProperty(methodName); if (lazyLoader.hasLoader(property)) { lazyLoader.load(property); } } }