My solution:
In order to do an ORM mapping one should understand first what he actually wants to see in the database. So when I realized that reasonable solution is to create several transition tables between descendants of Item
and Tag
, I understood, that this may be accomplished using @ManyToMany. And it works fine!
Listing below.
@MappedSuperclass
public class Item extends Model {
@Id
public Long id;
@ManyToMany(cascade = CascadeType.ALL)
public List<Tag> tags;
public String name;
<…> }
@Entity
public class Book extends Item {
public int pageNum;
<…> }
@Entity
public class CD extends Item{
public int size;
<…> }
@Entity
public class Tag extends Model{
@Id
public Long id;
public String text;
<…> }
PS I'd post also class and er diagrams, but currently I got no r8n to post images.