-->
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.  [ 1 post ] 
Author Message
 Post subject: ehcache assembly and not-null many-to-one
PostPosted: Wed Feb 18, 2004 2:13 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
hibernate 2.1.1
postgres 7.3.4
ehcache 0.7

I've got the relationship:

State -- *UsHouseDistrict

Here's the mapping:
Code:
<hibernate-mapping>

   <class
      name="District"
      table="District"
      batch-size="10"
      >

      <id
         name="id"
         unsaved-value="null"
         >
         <generator class="seqhilo"/>
      </id>

      <joined-subclass
         name="State"
         table="vgt_state"
         >
         <key column="id"/>

         <set
            name="usHouseDistricts"
            lazy="true"
            inverse="true"
            cascade="none"
            sort="natural"
            >

            <key
               column="state_id"
               >
            </key>

            <one-to-many
               class="UsHouseDistrict"
               />

         </set>

      </joined-subclass>

      <joined-subclass
         name="UsHouseDistrict"
         table="vgt_ushouse_district"
         >
         <key column="id"/>

         <many-to-one
            name="state"
            class="State"
            column="state_id"
            not-null="false"
            unique="false"
            cascade="none"
            outer-join="auto"
            />

      </joined-subclass>

   </class>

</hibernate-mapping>


Note that the UsHouseDistrict's State may be null and that a State's usHouseDistricts are held in a sorted set.

After I started caching the collection State.usHouseDistricts I started getting a NPE when the house districts were being assembled from the cache into the sorted set. I found that the compareTo() method used by UsHouseDistrict assumed that the state was not-null. In fact, all the existing house districts had a not null state even though this was not enforced in the db schema or the hibernate mapping.

So the question is ... is this how hibernate caching works? -- to, on fetching from the cache, only fill in the not-null (i.e. necessary) fields before possibly invoking a compareTo() / hashCode() / equals() operation? Related: will changing the relationship to not-null="true" fix the problem? Or have I found a bug? Is this at all related to the joined-subclass particulars of my mapping?


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

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.