title: Java hibernate/jpa how to create dynamic generic entity that is self related
body: <p>I would like to create dynamic and generic superclass with JPA/hibernate that will be extended for each hierarchical structured model like: role, page, directory, department, permission, tree.
  I would like to create with this object dynamic tree using recursion and java reflection</p>
  
  <p>it should look this way:</p>
  
  <p><img src="https://i.stack.imgur.com/MIJcz.png" alt="enter image description here"></p>
  
  <p>This entity should have reference to self entity.</p>
  
  <p>I would like it to be completely abstract and had no db table. Only extendet enities should have db.</p>
  
  <p>I've tried to achive this. But fail so long. <a href="https://stackoverflow.com/questions/27101716/apply-generic-class-mappedsuperclass-as-targetentity-error-manytoone-on-model">Here is my post about it</a></p>
  
  <p>I consider solutions:</p>
  
  <ul>
  <li>@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)</li>
  <li>@Any and @AnyMetaDef mappings</li>
  <li>@MappedSuperclass</li>
  <li>@Embeddable and @Embedded</li>
  </ul>
  
  <p>I hope someone will give some suggestions.</p>