jpa - How can I share an Entity for other entities' OneToMany -


i have entity this.

@entity class property extends baseentity {     @basic     private string name;     @basic     private string value; } 

the basic intention using entity other entities properties.

@entity class myentity extends baseentity {     @onetomany     private list<property> properties; }  @entity class yourentity extends baseentity {     @onetomany     private list<property> properties; } 

how can this? have define each owner's field in property?

@entity class property extends baseentity {     @basic     private string name;     @basic     private string value;     @manytoone(optional = true)     private myentity myentity;     @manytoone(optional = true)     private yourentity yourentity;     @manytoone(optional = true)     private otherentity otherentity; } 

basically solution represented here. there option create join table keep entity "cleaner" (and used manytomany. in of cases prefer use option provided [simplicity gooooood thing :) ], other colleagues got different view on problem.

tl.dr: provided code working , prefer it. there other ways bit slower etc.


Comments