Mantis - Resin
Viewing Issue Advanced Details
2033 major always 10-01-07 04:30 10-01-07 12:17
plehov  
westrupp  
normal  
closed 3.1.2  
fixed  
none    
none 3.1.3  
0002033: Amber One2Many and Many2Many relations doesn't work
Amber One2Many and Many2Many relations doesn't work on Resin 3.1.1, 3.1.2 and latest snapshot.
 

Notes
(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();
    }
  }