How do I map a set of string objects using JPA Annotations?

public class TestClass implements Serializable{
    private Integer id;
    private Set<String> mySet;

    public Integer getId() {
        return id;
    public Set<String> getMySet() {
        return mySet;

I get the following error.

Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: TestClass.mySet[java.lang.String]

or if I leave off the @OneToMany

org.hibernate.MappingException: Could not determine type for: java.util.Set, at table: test_class, for columns: [org.hibernate.mapping.Column(my_sets)]


You’ll find a pretty decent answer here. The rules for Lists apply to Sets too.

Leave a Reply

Your email address will not be published. Required fields are marked *