hibernate - bidirectional many-to-many association using a Map instead of a Set -


i'm having bear of time , suggestions appreciated.

i have bi-directional many-to-many association mapping between 2 entities (flashcard , tag) successfully represented java.util.set. i'd change collection type java.util.map.

here's excerpt of working mappings using set

<class name="flashcard" table="flashcard">      <id name="flashcardid" type="int" column="flashcard_id">         <meta attribute="scope-set">public</meta>         <generator class="native" />     </id>      <property name="question" type="string">         <meta attribute="use-in-tostring">true</meta>         <column name="question" not-null="true" unique="true" />     </property>      <set name="tags" table="flashcard_tag">         <meta attribute="field-description">tags flashcard</meta>         <key column="flashcard_id" />         <many-to-many class="tag"             column="tag_id" />     </set>  </class>  <class name="tag" table="tag">      <id name="tagid" type="int" column="tag_id">         <meta attribute="scope-set">public</meta>         <generator class="native" />     </id>      <property name="name" type="string">         <meta attribute="use-in-tostring">true</meta>         <column name="name" not-null="true" unique="true" />     </property>      <set name="flashcards" table="flashcard_tag" inverse="true">         <meta attribute="field-description">flashcards tag</meta>         <key column="tag_id" />         <many-to-many class="flashcard"             column="flashcard_id" />     </set>  </class> 

ok, said working i'd change collection type java.util.map.

i played mappings quite bit , able following partially work.

<class name="flashcard" table="flashcard">      <id name="flashcardid" type="int" column="flashcard_id">         <meta attribute="scope-set">public</meta>         <generator class="native" />     </id>      <property name="question" type="string">         <meta attribute="use-in-tostring">true</meta>         <column name="question" not-null="true" unique="true" />     </property>      <map name="tags" cascade="all" table="flashcard_tag">         <meta attribute="field-description">tags flashcard</meta>         <key column="flashcard_id" not-null="true" />         <map-key type="string" column="name" formula="name"/>         <many-to-many column="tag_id" class="tag"/>     </map>  </class>  <class name="tag" table="tag">      <id name="tagid" type="int" column="tag_id">         <meta attribute="scope-set">public</meta>         <generator class="native" />     </id>      <property name="name" type="string">         <meta attribute="use-in-tostring">true</meta>         <column name="name" not-null="true" unique="true" />     </property>      <map name="flashcards" inverse="true" cascade="all" table="flashcard_tag">         <meta attribute="field-description">flashcards tag</meta>         <key column="tag_id" not-null="true" />         <map-key type="string" column="question" formula="question" />         <many-to-many column="flashcard_id" class="flashcard"/>     </map>  </class> 

when these mappings "partially work" mean able use these mapping generate database tables , entity classes. entity classes did indeed include collection of type java.util.map. looked find , compiles without errors.

however, when run code runtime errors hibernate follows: org.hibernate.mappingexception: not determine type for: string, @ table: flashcard_tag, columns: [org.hibernate.mapping.formula( name )] @ org.hibernate.mapping.simplevalue.gettype(simplevalue.java:306)

the hibernate documentation shows example of bi-directional many-to-many association uses set. here's link docs.

summary

  • there 2 entities: flashcard , tag
  • the flashcard entity has collection of references other entities of type tag
  • the tag entity has collection of references other entities of type flashcard
  • this many-to-many, bi-directional association
  • flashcard_tag association table
  • the association represented java.util.set according hibernate documentation commonly used collection mapping.
  • i want use java.util.map instead of java.util.set


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -