views:

2103

answers:

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

    @Id
    @GeneratedValue
    public Integer getId() {
     return id;
    }
    @OneToMany(cascade={CascadeType.ALL})
    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)]

A: 

are you answering your own question? Or is there something wrong with your solution? If so, do you get an error message when using this?

Fortega
+2  A: 

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

Cogsy
+1  A: 

Ooh oh, I had to do this one.

@CollectionOfElements(targetElement = String.class)

Joshua
This is also what I had to do, but it is hibernate specific. In my situation that's fine with me.
ScArcher2