Here is my problem. I have an article that has a bunch of keywords/tags (where one article can have multiple tags and one tag can go to multiple articles. Here what I'd like to achieve:
@Entity
class Article
{
String content;
Set<Tags> tags
}
@Entity
class Tag
{
Integer id
String name;
... //other fields
}
In other words I want to avoid @ManyToMany
mapping or making my own pseudo ManyToMany class
(in EJB 3.0). Is 开发者_开发百科there a way for the Article to see a set of tags while Tags don't see the articles they are connected?
Your relationship is inherently ManyToMany whether you want to see the Articles from the Tags or not.
You said it yourself: "one article can have multiple tags and one tag can go to multiple articles". There is a "multiple" on both sides.
This means you will need an intermediary join table in the database no matter how you map this into your entity model.
精彩评论