title: develop a class that can hold various types (primitive, list, map) in one field
body: <p>I would like to have a java class (MyClass) that holds an id, a name and a value, where the value can be a primitive type (string, int, long) or a list or a map. The class will be persisted by using JPA 2.0</p>
  
  <p>My first thought were about a class with the following structure:</p>
  
  <pre><code> ,-----------.
   | MyClass   |
   |...........|
   | id        |
   | name      |
   | index     |
   | key       |
   | value     |
   '------------
  </code></pre>
  
  <p>that resolve by getter and setter if a primitive or a list or a map ist stored - depending on the {index, key, value} combination.</p>
  
  <p>An alternative would be an inheritance hierarchy:</p>
  
  <pre>
                       .................
                       | AbstractClass |
                   ,.- ................''--..__
              _,-''            |               `--.._
           ,-'                 |            ................
  ......................       |            |MapValueClass |
  | PrimitiveValueClass|       |            ................
  ......................       |
                      ..................
                      | ListValueClass |
                      ..................
  </pre>
  
  <p>Keeping in mind, that I use JPA: is there a "standard way" or a "best practice" for this problem? Some way, that I can use myClass and access the value by a getter and decide with  instanceof Map/List/Integer what sort of value is hold?</p>