hibernate - Storing structured comments in MYSQL database using Java JPA and Spring Data -
using spring data , java jpa, store comment threads in mysql table. comments on chunk of data, , every comment can have number of child comments (think reddit). wondering if java class makes sense fulfill needs.
@entity public class comment extends identified { // comment data @column(nullable=false) private string data; // parent comment @manytoone(fetch=fetchtype.lazy) @joincolumn(nullable=true) private comment parent; // sub comments @onetomany(fetch=fetchtype.eager) @joincolumn(nullable=true, mappedby="parent") private set<comment> children; public comment() { } ....
to clarify, main concern regards having both manytoone , onetomany relationship same class. seems ugly, way express relationship.
i assure mapping normal, usual. 2 relationships (many-to-one , one-to-many) realized in db using different concepts , not collide. relationship bidirectional, both mappings represent different ends of 2 different links (one relation parent, relation child).
Comments
Post a Comment