-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: null index column for collection
PostPosted: Wed Mar 08, 2006 1:48 pm 
Newbie

Joined: Wed Mar 08, 2006 1:08 pm
Posts: 2
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>


Top
 Profile  
 
 Post subject: remove uncertainty
PostPosted: Wed Mar 08, 2006 2:00 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I would suggest using placeholder which in reality is not a placeholder but real name for the default locale :)
It removes any ambiguity about what is default: French, Russian, Chinese? Just specify it explicitly and remove all the uncertainty

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: cannot represent uncertainty
PostPosted: Wed Mar 08, 2006 3:10 pm 
Newbie

Joined: Wed Mar 08, 2006 1:08 pm
Posts: 2
Thanks for such a prompt reply, kgignatyev.

Unfortunately, your solution will make it impossible to represent Strings where the language is uncertain, not specified, or not applicable. Such situations will occur in my project so the locale must be retrieved as it was entered.
If Hibernate will absolutely not accept null Map keys, I'll just have to create a "" Locale for these cases and use it whenever setLanguage() is called with a null argument.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.