title: (unsaved) data in groovy in many-many relationship
body: <p>My Data Domain:</p>
  
  <pre><code> class Course{
  List teacherCourse
  static hasMany = [courseByMultipleTeacher:TeacherCourse]
  }
  
  class Teacher{
      String name
      List teacherForCourses
      static hasMany = [teacherForCourses:TeacherCourse]
  }
  
  class TeacherCourse{
  Course course
  Teacher teacher
  static mapping={
              id composite: ['teacher','course']
  }
  
  }
  </code></pre>
  
  <p>And in my controller:</p>
  
  <pre><code>save(){
  Teacher teacherInst = new Teacher()
  teacherInst.name = "T1"
  teacherInst.save(flush:true)
  
  Course c1 = Course.findById(3)
  Course c2 = Course.findById(4)
  
  def teacherCourseA = new TeacherCourse(teacher:teacherInst, course:c1)
  def teacherCourseB = new TeacherCourse(teacher:teacherInst, course:c2)
  teacherInst.addToTeacherCourse(teacherCourseA)
  teacherInst.addToTeacherCourse(teacherCourseB)
  teacherInst.save(flush:true)
  
  //Output is: (unsaved) . Why?
  println(Teacher.findById(teacherInst.id).teacherForCourses.get(0));
  
  }
  </code></pre>
  
  <p><strong>Output</strong>
  net.school.teacher.TeacherCourse : (unsaved)</p>
  
  <p>The Teacher and TeacherCourse gets saved in database (PostgreSQL). I get the (unsaved) message when ever I try to retrieve the value from the list. I am not sure why is that. Any help would be appreciated. I looked up this <a href="https://stackoverflow.com/questions/4810574/grails-gorm-object-references-an-unsaved-transient-instance">link</a>, but could not solve the problem.</p>