title: JPA mapping for a List or Set<String>
body: <p>Being new to ORM, I'd like to find a way to define a simple (meaning without an additional entity) mapping for a list (or a set) of strings within an entity. I found this sample:</p>
  
  <pre><code>import java.util.Set;
  
  import javax.persistence.CollectionTable;
  import javax.persistence.Column;
  import javax.persistence.ElementCollection;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  
  @Entity
  public class Book {
    @Id
    @GeneratedValue
    private Long id;
  
    @ElementCollection
    @CollectionTable(name = "tags")
    private Set&lt;String&gt; tags;
  
    public Long getId() {
      return id;
    }
  
    public void setId(Long id) {
      this.id = id;
    }
  
    public Set&lt;String&gt; getTags() {
      return tags;
    }
  
    public void setTags(Set&lt;String&gt; tags) {
      this.tags = tags;
    }
  }
  </code></pre>
  
  <p>which seems to fit my needs. However, processing this class with Eclipse's <code>hibernate3-maven-plugin:2.2:hbm2ddl</code>, I end up with the following error: </p>
  
  <blockquote>
    <p>[ERROR] Failed to execute goal
    org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl (default) on
    project test-database: Execution default of goal
    org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm2ddl failed: Could
    not determine type for: java.util.Set, at table: Book, for columns:
    [org.hibernate.mapping.Column(tags)] -> [Help 1]</p>
  </blockquote>
  
  <p>Specifying <code>@ElementCollection(targetClass=String.class)</code> did not help. Adding a column definition to the <code>tags</code> field (<code>@Column(name = "tags", columnDefinition="character varying (255)", nullable = false)</code>) leads to a successful build but produces this SQL:</p>
  
  <pre class="lang-sql prettyprint-override"><code>create table Book (
      id int8 not null,
      tags character varying (255) not null,
      primary key (id)
  );
  </code></pre>
  
  <p>which is not what I want, as I was expecting to end up with a <code>tags</code> table linked to the books table. Could someone point me to the right direction ? Thank you.</p>