Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


how do you map a map in hibernate using annotations using -'java,hibernate,orm,mapping'


how do you map a map in hibernate using annotations  using -'java,hibernate,orm,mapping'



Using annotations how do you map a field in an entity which is a "Map" (Hashtable) of String to a given object? The object is annotated and instances of it are already stored in the hibernate databse.

I've found the syntax for definging a map with a simple key and value as such:

<class name="Foo" table="foo">
    ...
    <map role="ages">
         <key column="id"/>
         <index column="name" type="string"/>
         <element column="age" type="string"/>
     </map>
 </class>


And oddly with an entity as the key and a simple type as the value like so:

<class name="Foo" table="foo">
    ...
  <map role="ages">
    <key column="id"/>
    <index-many-to-many column="person_id"
         class="Person"/>
    <element column="age" type="string"/>
  </map>
</class>
<class name="Person" table="person">
    ...
    <property name="name" column="name"
         type="string"/>
</class>


But I don't see how to do this for a simple key to element mapping, and I don't see how to do this using annotations.
    

asked Sep 7, 2015 by rajesh
0 votes
21 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...