2 Replies Latest reply on Apr 18, 2008 3:47 AM by jwenting

    Newbie problem with persitence

    stareagle

      Hello,

      I have a problem with the persitence in my first JBoss application. There two Beans, which have an 1:n relationship.

      The problem: When I'am deploying the application, JBoss complains that I'am trying to use the OneToMany annotation on a none collection:

      org.hibernate.AnnotationException: Illegal attempt to map a non collection as a @OneToMany,...


      The relevant code from the class:

      @OneToMany(mappedBy = "employer", cascade = CascadeType.ALL)
      public Vector<User> getEmployees() {
       return this.employees;
      }
      
      public void setEmployees(Vector<User> employees) {
       this.employees = employees;
      }


      The attribute employees is a java.util.Vector. I'am very sure that a Vector is a Collection. I also tried other classes like LinkedList with the same result.

      Can anybody help me?

      Greetings

      Stareagle

        • 1. Re: Newbie problem with persitence
          jaikiran

          As per the EJB3 spec, Vector is not supported collection type for OneToMany mapping:


          Collection-valued persistent fields and properties must be defined in terms of one of the following collection-valued interfaces regardless of whether the entity class otherwise adheres to the JavaBeans method conventions noted above and whether field or property-based access is used:
          java.util.Collection, java.util.Set, java.util.List[4], java.util.Map.[5]
          For collection-valued persistent properties, type T must be one of these collection interface types in the method signatures above. Generic variants of these collection types may also be used (for example, Set<Order>).


          • 2. Re: Newbie problem with persitence

            Vector shouldn't be used in any code written past circa 1999 anyway, except for code that needs to talk to legacy classes like some Swing components (and even then, I'd sooner implement my own subclasses than use the Vector based ones).