I am trying to do something like this, but using @One-To-Many instead of @ElementCollection.
public class Book {
...
@ElementCollection
Set<String> tags;
...
}
This creates two tables, one for Book and one for the Tags with (BookID, Tag) which works fine, except for the fact that I can't use Criteria with @ElementCollection.
So I changed it and made a wrapper class for the tags:
public class Book {
...
@OneToMany(...)
Set<BookTag> tags;
...
}
public class BookTag {
...
String tag;
...
}
The problem is that using @OneToMany annotation hibernate creates 3 tables: one for the books, one for the tags, and one to join books and tags. This solutions works perfectly but I would like to have 2 tables instead of 3, since the Tag class contains only a String.
Is there any way to use @OneToMany and make hibernate create 2 tables like it does with @ElementCollection ?