In jpa I have some entity (Content
and Product
for now but more can come) that should join to Comment
entity.
Problem is I don't want to have extra field(and column in table) in Comment entity for each join entity (Products, Contents..) because these entities will increase in future.
I find one semi-solution is to use single table inheritance and create concrete Comment class like CommentContent
, CommentProduct
, and use discriminator column but joining to entities (Content and Product) still remain.
what do you suggest?
Edit:
sample relation for example between Comment and Content will be @MayToOne that many Comments belongs to one Content and so for Product..
Edit 2
in pure table relationship schema (without ORM like hibernate/jpa) I can and I do this kind of solution: add to column in comment table 1-item_type and 2-item_id witch item_type specify other side table name (product, content in my question) and item_id specify foreign key to table that it name is at item_type column
How can I model this in Jpa/hibernate ORM?