I have a very simple bean called LangString with fields for a Locale and a String. My problem occurs when I create a HashMap of them with the Locale as the key and I use a null Locale for default and/or language-neutral text. The HashMap does not complain about null keys and Hibernate successfully persists them to the database but will not read them back. Whenever I try, org.hibernate.persister.collection.AbstractCollectionPersister.readIndex() throws a "null index column for collection" exception.
Is there a way of telling Hibernate to allow null keys in Maps or will I have to create some kind of placeholder Locale for "language-neutral"?
Hibernate version:
3.1
Mapping documents:
Code:
<class name="vdex.LangStringBag" >
<id name="id" type="integer" column="langstringbag_id">
<generator class="sequence">
<param name="sequence">langstringbag_seq</param>
</generator>
</id>
<map name="langstrings" inverse="true" cascade="all-delete-orphan">
<key column="langstringbag_id" />
<map-key formula="language" type="locale" />
<one-to-many class="vdex.LangString" />
</map>
</class>
<class name="vdex.LangString" >
<id name="id" type="integer" column="langstring_id">
<generator class="sequence">
<param name="sequence">langstring_seq</param>
</generator>
</id>
<many-to-one name="owner" column="langstringbag_id" not-null="true" />
<property name="language" type="locale" />
<property name="string" type="text" />
</class>