(0002319)
westrupp
10-01-07 12:17
|
Amber is working fine. The OneToMany/ManyToMany examples have been updated. Both servlets need a transaction enclosing the query and the getCourses()/getStudents() calls. Otherwise, the query would return detached entities and any attempt to retrieve the relations would return empty collections.
// ManyToManyServlet.java
...
public void service(HttpServletRequest req, HttpServletResponse res)
throws java.io.IOException, ServletException
{
// ...
try {
_entityManager.getTransaction().begin();
Query allStudent = _entityManager.createQuery("SELECT o FROM Student o");
List students = allStudent.getResultList();
for (int i = 0; i < students.size(); i++) {
Student student = (Student) students.get(i);
out.println("<h3>" + student.getName() + "</h3>");
Collection courses = student.getCourses();
// ...
}
} finally {
_entityManager.getTransaction().commit();
}
} |