I have a scenario where I have a Object called Page, and another object called Tag, relationship between these two is Page has Tags(many to many), but the same Tags can also shared with Product, here also the relationship is same Product has Tags (many to many).
In normal scenario I will create a type column in Tag where type may be Enum value (product, page) and use query like SELECT * from Tags where parent_id = page_id and type = page.
How to do this in JPA (how to create this relationship and how to query data)
I think you should create two tables of associations. One to associate Pages with tags, one to associate Products with tags. The code:
to select corresponding tags for page, use
to select corresponding tags for product, use