2 Replies Latest reply on Dec 18, 2006 10:23 PM by vk101

    @OneToMany with String as the many


      If I have an entity with a collection of Strings (e.g. a Person with many FirstNames), how would I map this to database tables using annotations? I tried a @OneToMany on the Set FirstNames, but this doesn't work.

      Is my only option really to make FirstName an @Entity?

      Is there any other way to get this to work without making FirstName an entity (i.e. without using @OneToMany?)

        • 1. Re: @OneToMany with String as the many
          Andrew Dale Newbie


          try to annotate it with org.hibernate.annotations.CollectionOfElements.



          • 2. Re: @OneToMany with String as the many

            Thanks, that worked.

            When validating the FirstNames with Hibernate Validation annotations, what would you annotate? The collection's getter (i.e. getFirstNames()) or the getter of the individual element (i.e. getFirstName())?

            In the collection's getter, I was surprised to find that the unique column was created on the database table when I entered @Column(unique=true). It was created on the correct column of the generated table for storing the elements. So if that works, should I be able to put all annotations there or should I put it on the getter method bound to the firstName form field?