1 Reply Latest reply on Apr 16, 2007 9:22 AM by fhh

    unidirectional Many-To-Many relationships

    urkens_jp

      When trying to model unidirectional M-t-M relations I get a org.hibernate.MappingException.
      I tried the example from Mastering EJB3.0 from Wiley Publishing:

      @Entity(name="CourseUni")
      public class Course implements Serializable {
       private int id;
       private String courseName;
      
       private Collection<Student> students = new ArrayList<Student>();
      
       public Course() { id = (int)System.nanoTime(); }
      
       @Id
       public int getId() { return id; }
      
       public void setId(int id) { this.id = id;}
      
       public String getCourseName() { return courseName;}
      
       public void setCourseName(String courseName) {
       this.courseName = courseName;
       }
      
       public Collection<Student> getStudents() {
       return students;
       }
      
       public void setStudents(Collection<Student> students) {
       this.students = students;
       }
      }
      
      @Entity(name="StudentUni")
      public class Student implements Serializable {
       private int id;
       private String name;
       private Collection<Course> courses = new ArrayList<Course>();
      
       public Student() { id = (int)System.nanoTime(); }
      
       @Id
       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; }
      
      @ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
       @JoinTable(name="STUDENTUNI_COURSEUNI")
       public Collection<Course> getCourses() {
       return courses;
       }
      
       public void setCourses(Collection<Course> courses) {
       this.courses = courses;
       }
      
      


      When deploying this on JBOSS-4.0.5.GA following Exception is thrown:
      :49:41,641 DEBUG [org.jboss.ejb3.ServiceDelegateWrapper] Starting failed persistence.units:jar=tutorial.jar,unitName=tempdb
      javax.persistence.PersistenceException: org.hibernate.MappingException: Could not determine type for: java.util.Collection, for columns: [org.hibernate.mapping.Column(students)]